E3SM-Project / E3SM

Energy Exascale Earth System Model source code. NOTE: use "maint" branches for your work. Head of master is not validated.
https://docs.e3sm.org/E3SM
Other
347 stars 354 forks source link

MCT compile breaks when using -real-size 64 intel compiler flag #2870

Open AaronDonahue opened 5 years ago

AaronDonahue commented 5 years ago

If the intel fortran compiler flag -real-size 64, which is equivalent to -autodouble or -r8, is used the build will break during MCT. We tracked the issue down to the file: cime/src/externals/mct/mpeu/m_realkinds.F90 which has the following block of code that conflicts with the compiler flag option:

#ifdef SELECTEDREALKIND
     integer,parameter :: SP = selected_real_kind( 6)  ! 32-bit real, on most platforms
     integer,parameter :: DP = selected_real_kind(12)  ! 64-bit real, on most platforms
#else
     integer,parameter :: SP = kind(1.  )
     integer,parameter :: DP = kind(1.D0)
#endif

where SP and DP are defined. The break in the build is in an "interface" defined in m_mpif90.F90.

AaronDonahue commented 5 years ago

Pinging @bartgol and @ambrad who helped me track this down.

bartgol commented 5 years ago

The error showed up in m_mpif90.F90 module, where two "overloads" of MP_Type were given, for SP and DP. If the default real is 64 bits, and SELECTEDREALKIND is not defined, you end up with SP=DP. This yielded to the two overload to be exactly the same, which meant the interface procedure could not pick one.

Possible solution: Make SP always denote single precision, and DP always denote double precision. This means to eliminate that ifdef, and always pick the first branch.

worleyph commented 5 years ago

FYI - CCSM went through an extended exercise to eliminate dependence on compiler flags to autopromote variables, adding explicit typing everywhere, including constants. This has been maintained (as far as I know) in CESM and E3SM. @rljacob , any comments about MCT supporting (or deliberately not supporting) , for example, -r8 ?

rljacob commented 5 years ago

Yes auto-promotion is not allowed in E3SM fortran builds.

rljacob commented 5 years ago

Although the behavior I'd expect is that MCT just ignores any auto-promotion flags. So this is worth looking at.

bartgol commented 5 years ago

You mean you thought MCT would ignore the -real-size 64 flag?

rljacob commented 5 years ago

No I thought -r8 would have no effect but you get a build error even with that.

A workaround is go ahead and define SELECTEDREALKIND. You can then build with any of the autopromotion flags. Note that you could still compile an application that links against MCT with autopromotion even if MCT is compiled without it.

IIRC, we were concerned about using the intrinsic selected_real_kind() because we wanted MCT to require only an F90 compiler and that function is in the F95 standard. I suppose we could drop that now. There is similar code in CIME that uses selected_real_kind and I believe E3SM/CIME requires Fortran2008.