MPAS-Dev / MPAS-Model

Repository for MPAS models and shared framework releases.
237 stars 316 forks source link

NetCDF-Fortran not linking #21

Open cponder opened 9 years ago

cponder commented 9 years ago

I'm getting the following linkage errors in the MPAS-A 3.3 build:

undefined reference to `netcdf_mp_nf90_inquire_'
undefined reference to `netcdf_mp_nf90_inquire_attribute_'
 undefined reference to `netcdf_mp_nf90_inq_attname_'
undefined reference to `netcdf_mp_nf90_inq_varid_'
undefined reference to `netcdf_mp_nf90_inquire_variable_'
<etc.>

When I try the compile-command on the command-line, I can get it to link by adding

 -L$NETCDF_F/lib -lnetcdff

I've tried adding these settings to the build environment

 export LDFLAGS="-L$NETCDF_F/lib -lnetcdff -L$NETCDF/lib -lnetcdf"
 export LIBS="-L$NETCDF_F/lib -lnetcdff"
 export FFLAGS="-L$NETCDF_F/lib -lnetcdff"
 export FCFLAGS="-L$NETCDF_F/lib -lnetcdff"

but they never show up on the problematic compile line

mpif90 -O3 -o atmosphere_model driver/*.o -L. -ldycore -lops -lframework -L/shared/apps/rhel-6.2/tools/cponder/PIO-1.9.15/Intel-15.0/lib -lpio -L/shared/apps/rhel-6.2/tools/cponder/PNetCDF-1.6.0/OpenMPI-1.8.4_Intel-15.0_CUDA-6.5/lib -lpnetcdf -L/shared/apps/rhel-6.2/tools/cponder/NetCDF-4.3.3-rc3/Intel-15.0_HDF5-1.8.14_OpenMPI-1.8.4_CUDA-6.5/lib -lnetcdf -I./external/esmf_time_f90 -L./external/esmf_time_f90 -lesmf_time

How do I pass the NetCDF-Fortran info into the build?

douglasjacobsen commented 9 years ago

@cponder: It looks like you're trying to build the atmosphere model, so you should probably look at their users guide

Chapter 3 has instructions for how to build the model, but the short answer to your question is that all netcdf libraries must be installed in the same location and you pass that location using the NETCDF environment variable. Once you set that, all the library information is internally dealt with (i.e. you don't need to set LDFLAGS, LIBS, FFLAGS, or FCFLAGS).

cponder commented 9 years ago

The PIO, NETCDF and PNETCDF variables are already set in my envoronment. Note that NetCDF-C and NetCDF-F are no longer bundled-together, and are released with different version numbers. Do you have a NETCDF_F environment variable?

douglasjacobsen commented 9 years ago

@cponder No, you have to install NetCDF-C and NetCDF-F into the same directory. Even if they have different version numbers.

cponder commented 9 years ago

Why don't you just fix the Makefile?

douglasjacobsen commented 9 years ago

@cponder Most of our builds use older netcdf libraries that are bundled together. It's possible for us to change the Makefile to have a NETCDF_F flag in the future, but it likely won't happen in a short amount of time.

cponder commented 9 years ago

I don't get why the compiler doesn't pick up the -L$NETCDF_F/lib -lnetcdff settings from the LDFLAGS or FCFLAGS variables, are you clearing these?

douglasjacobsen commented 9 years ago

It's not that we're clearing them. We just don't use them. So, setting these variables doesn't affect the build at all.

cponder commented 9 years ago

This patch to the top-level Makefile worked:

269 ifneq "$(NETCDF_F)" ""
270         CPPINCLUDES += -I$(NETCDF_F)/include
271         FCINCLUDES += -I$(NETCDF_F)/include
272         LIBS += -L$(NETCDF_F)/lib -lnetcdff
273 endif

Note that (1) it only uses the NETCDF_F it is set, and the

263         ifneq ($(wildcard $(NETCDF)/lib/libnetcdff.*), ) # CHECK FOR NETCDF4

check is still in place, so a merged NetCDF-C + NetCDF-F directory will still work. Can you add this to your next bugfix release? The patch doesn't add any autodetecting, you have to explicitly use the NETCDF_F variable. Also it doesn't force the user to set NETCDF_F, although in the future we might want to remove the libnetcdff autodetection from NETCDF and simply set NETCDF_F=$NETCDF as the default.

cponder commented 9 years ago

This one changes more lines but I think is cleaner overall

257 ifneq "$(NETCDF)" ""
258         CPPINCLUDES += -I$(NETCDF)/include
259         FCINCLUDES += -I$(NETCDF)/include
260         LIBS += -L$(NETCDF)/lib -lnetcdf
261         ifneq ($(wildcard $(NETCDF)/lib/libnetcdff.*), ) && ifeq "$(NETCDF_F)" "" # CHECK FOR NETCDF4
262                 NETCDF_F=$(NETCDF)
263         endif # CHECK FOR NETCDF4
264 endif
265 
266 ifneq "$(NETCDF_F)" ""
267         CPPINCLUDES += -I$(NETCDF_F)/include
268         FCINCLUDES += -I$(NETCDF_F)/include
269         LIBS += -L$(NETCDF_F)/lib -lnetcdff
270 endif

So $NETCDF_F is used if it is set; otherwise we autodetect the $NETCDF/lib/libnetcdff.* as before.

cponder commented 9 years ago

Doug -- I'm having trouble building the PIO library with OpenMPI. Has MPAS-A only been tested with the Intel compiler & Intel MPI?

     -- Carl

This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by

reply email and destroy all copies of the original message.

mgduda commented 9 years ago

@cponder We've primarily used MPICH with MPAS-Atmosphere, though I believe a number of MPAS-Ocean developers use OpenMPI. Generally, I don't think there's a preference on the MPAS side for any particular MPI implementation. If this is an issue in building PIO, however, you might like to get in contact with the PIO developers, since PIO is a library developed completely independently from MPAS.