Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

The gptl library and the use of a trailing underscore in the names of CESM routines

djw

David Webb
New Member
In porting CESM to a small gcc based computer, I have been trying to build the small test example and reached what appears to be the final link step when 'Building cesm".

The linker produces a large number of error messages indicating that it cannot link between the fortran and C routines within the gptl library (libgptl.a). The link stage also had undefined references to 'chdir_' and 'system_'.

I checked the contents of 'libgptl.a' using the "nm" command and found in the case of the gptlstop routine, that the name appears in three of the *.o files:

gptl.o:
...
0000000000003b76 T GPTLstop
0000000000004040 T GPTLstopf
00000000000042ca T GPTLstopf_handle
0000000000003db9 T GPTLstop_handle
0000000000003a2a T GPTLstop_instr
...

f_wrappers.o [Compiled from f_wrappers.c]
...
0000000000000218 T gptlstop
U GPTLstopf
U GPTLstopf_handle
0000000000000226 T gptlstop_handle
...

perf_mod.o [Comiled from perf_mod.F]
...
U gptlstop_
...
00000000000006c7 T __perf_mod_MOD_t_stopf


where '...' indicates lots of other output. From this I conclude that "perf_mod.o" requires a link to 'gprlstop_', but "f_wrappers.o" only supplies 'gprlstop' without the underscore.

The directory used by the script 'case.build', to compile the gptl library is "cime/src/share/timing/", although the same routines are also in
"cime/src/externals/pio1/timing" and "cime/src/externals/pio2/src/gptl".

I checked "perf_mod.F" and " f_wrappers.c", and was surprised to see that the fortran file does not use 'iso_binding_c' or 'bind(c)'. Instead the C file has a series of if/elif statements with options FORTRANCAPS/INCLUDE_CMAKE_FCI/FORTRANUNDERSCORE/FORTRANDOUBLEUNDERSCORE without explanation. Presumably the code predates Fortran 2003.

I tried adding -DFORTRANUNDERSCORE to the options used when compiling C, as some of the machines do for C++ in the standard config_machines.xml file. This solved the problem for libgptl.a - but I find it odd that none of the many gnu compiler machines listed use this flag. Is there another flag I should have used?

At the moment I still have the undefined references to 'chdir_' and 'system_'. Is this a separate issue or is there a single solution to both this and the libgptl.a problem?

Regards, David.
 

jedwards

CSEG and Liaisons
Staff member
Compare your flags to the gcc compiler to what is used on some of the other systems. You didn't tell me which version of cesm you are trying to port but in
cesm2.1 this is in file cime/config/cesm/machines/config_compilers.xml and for gnu compilers you should have
-DFORTRANUNDERSCORE -DNO_R16 -DCPRGNU

these are default settings for the gnu compiler that you must have removed?
 

djw

David Webb
New Member
I am using the git commit : "release-cesm2.1.4".

The gnu section of config_compilers.xml you refer has the flags you mention only in CPPDEFS and this is commented out. SUPPORTS_CXX is also set to false. Following this, my own compilers file has no CPPDEFS section and also sets SUPPORTS_CXX to false. Nothing was removed.

However I added the flags you listed to CFLAGS and FFLAGS. This time everything linked and I received the message:
MODEL BUILD HAS FINISHED SUCCESSFULLY

So many thanks.

David.
 
Top