Compiling Netcdf 3.6.2 on an AMD-64 Linux Platform

Discussion on computers, ROMS installation and compiling

Moderators: arango, robertson

Post Reply
Message
Author
baum

Compiling Netcdf 3.6.2 on an AMD-64 Linux Platform

#1 Unread post by baum »

Needing to spin up on ROMS 3.0, I've spent the last day or so on the prerequisite task of compiling NetCDF 3.6.2. I've got dual AMD 64-bit processors on a Linux 2.6.9 platform (i.e. Fedora Core 3), and the PGI 7.0, Pathscale 3.1, Intel 9.1 and gfortran 4.3.0 compilers to work with.

What follows is what I've found thus far. I've not been completely successful, but I've spent a lot of time discovering some fairly subtle compilation issues, and hope that these notes might help others prevent the sort of head-smashing, hair-pulling and mule-skinner-talking in which I've been engaged over the last couple of days.

I'm starting with a section on general issues that need to be recognized and dealt with for compiling and installing NetCDF using any compler/platform combination (although this is undboubtedly a lot more Linux-centric than I realize).

---------------------------------------------------------------

GENERAL CONSIDERATIONS FOR INSTALLING NetCDF 3.6.2:

If Candide were doing this in his ideal(ized) world, he would hopefully enter the following commands:

tar xzvf netcdf-3.6.2.tar.gz
cd netcdf-3.6.2
./configure
make
make test
su
make install

to install the NetCDF libraries and, after tweaking the compiler specification in the "makefile" and the NetCDF library path in the approprate *.mk in the Compilers subdirectory, would simply enter "make" in the upper-level ROMS directory and obtain a binary file ready to go. Unfortunately, in the real world your experience will more often than not be similar to those of Candide. Here are a series of specific suggestions that will hopefully obtain you a workable NetCDF library if Candide's method doesn't work.

Note carefully that all of this is specific to version 3.6.2 of the NetCDF library package which, at this writing, is the most up-to-date stable version of the NetCDF 3 series. This may not and probably will not work on previous versions of the 3 series.

1. Do not specify the "--enable-shared" flag when configuring the NetCDF code. ROMS does not like the shared versions of the libraries and, if both are present in the NetCDF library directory, the shared versions will be grabbed first during the linking phase and crash the ROMS compilation.

2. You can specify the location in which you want the NetCDF files installed via the "--prefix=" configuration flag. In my case an example is:

./configure --prefix=/opt/pathscale/netcdf-3.6.2

This will cause "bin", "include", "lib" and "share" directories to be created under the specified path into which the compiled library will be installed. How you specify this will depend on your computer setup, your privileges and various other considerations. I do it this way because I have several compilers and have found this the easiest way to keep track of the various packages I install using the different compilers.

If you do NOT specify this, it will be set to the default value of "/usr/local". Keep this in mind when you get to #7 below.

3. Both environment variables F90 and FC need to be specified as the location of your Fortran compiler if you want the f90 subdirectory containing the Fortran 90 interface to be compiled using your preferred F90 compiler. If you don't set both of these, the configuration script will search your binary paths for various F90 compiler names it recognizes and, upon finding one, will set the environment variables for you. If it finds none and you specify none, then the F90 interface will not be compiled.

4. If you are explicitly specifying your F90 compiler via the environment variables, it is a good idea to specify the full path to the binary rather than just the binary name. That is, you want to specify (under the bash shell in this example):

export F90=/opt/pgi/linux86-64/7.0-7/bin/pgf90

rather than

export F90=pgf90

The "/opt/pgi/linux86-64/7.0-7/bin/" portion of that first string will vary according to your compiler location.

If you've only got a single F90 compiler, then this probably won't be an issue. If you have more than one F90 compiler, though, major headaches can result from not being extremely specific about such things.

5. Having specified your F90 compiler, if you want to also specify the compilation flags for it rather than having the compiler do it for you, then you must set them using the FCFLAGS environment variable. This isn't something to spend too much time worrying about, though. The compiler defaults are quite reasonable, usually "-O2". The only time I'd bother with tinkering with this would be if - after compiling and install the NetCDF libraries - a problem occurred when linking with the ROMS code.

6. If you've done all the above and the library has successfully compiled, then enter "make test" for the package to run its series of self-tests. If an error occurs when it is performing the F90 test subsection, it is a highly probable sign that you will encounter problems when attempting to link with ROMS. Go ahead and try linking with ROMS anyway as it might just work, but if it doesn't then the error messages from the self-test results will be another useful diagnostic resource for identifying and solving your problem.

7. Be sure to check and possibly change the NetCDF library path variables that are set in the
*.mk file in the Compiler subdirectory that corresponds to the OS/compiler combination your are using. For example, in the Linux-path.mk file the appropriate section is:

ifdef USE_NETCDF4
NETCDF_INCDIR ?= /usr/local/netcdf4/include
NETCDF_LIBDIR ?= /usr/local/netcdf4/lib
HDF5_LIBDIR ?= /usr/local/hdf5/lib
else
NETCDF_INCDIR ?= /opt/pathscale/netcdf-3.6.2/include
NETCDF_LIBDIR ?= /opt/pathscale/netcdf-3.6.2/lib
endif

Herein I've changed the NETCDF_INCDIR and NETCDF_LIBDIR specifications to the locations I specified in the example in #2 above.

8. Even if you follow this prolix advice to the letter, each compiler will probably have another set of vexing issues of its very own. See below for my progress in that area.

----------------------------------------------------------------

PGI 7.0

The official PGI instructions can be found at:

http://www.pgroup.com/resources/netcdf/ ... _pgi60.htm

The environment variables that worked for me are:

export CC=gcc
export CFLAGS="-O2 -g"
export CPPFLAGS="-DpgiFortran"
export CXX=g++
export CXXFLAGS="-O2 -g"
export F90=/opt/pgi/linux86-64/7.0-7/bin/pgf90
export FC=/opt/pgi/linux86-64/7.0-7/bin/pgf90
export F77=/opt/pgi/linux86-64/7.0-7/bin/pgf90
export FCFLAGS="-O2 -g"
export FFLAGS="-O2 -g"

and the configure parameters:

./configure --prefix=/opt/pgi/netcdf-3.6.2

The Netcdf library will compile and install with the --enable-shared flag as well, but while the static library will successfully link during the ROMS compile, the shared libraries will not, so avoid the shared libraries flag. Also, while I couldn't find it mentioned in the documentation, you need to define the F90 environment variable or the f90 portion of the Netcdf library will not be compiled. The online documentation explains that the configure script will look for an F90 compiler if none is specified, and since I haven't specified any in my binpath, I had to set the F90 environment variable.

I should also mention that since I have all the compilers installed in the /opt hierarchy (e.g. /opt/intel, /opt/pgi etc.), I've not included the library paths for all in the ld.so.conf definitions. For me, this required that I specify the full path to the compiler rather than just the aliased name. That is, I had to specify:

export F90=/opt/pgi/linux86-64/7.0-7/bin/pgf90

irather than:

export F90=pgf90

I achieved a successful compile of the most recent ROMS SVN version using this method and the standard compile flags in the Linux-pgi.mk file.

---------------------------------------------------

Pathscale 3.1

The official instructions from PathScale can be found at:

http://www.pathscale.com/node/47

The prescription found at the Pathscale site worked for me. They prescribe:

export CC=pathcc
export CFLAGS='-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2 -g '
export CPPFLAGS=-Df2cFortran
export CXX=pathCC
export FC=pathf90
export FFLAGS='-O2 -g '
export CXXFLAGS='-O2 -g '

./configure --prefix=/opt/pathscale/netcdf-3.6.2
make
su
make install

I should note that I had many difficulties with the compile until I set these and these only, i.e. also setting F77, F90 etc. did not work. If any relevant environment variables other than those they have listed are set it can and probably will bollix the compile. You do not want to specify --enable-shared for this one, either.

Unfortunately, when I attempted to compile ROMS - using the standard flags found in the Linux-path.mk file - the compile crashed with the messages:

ROMS/Bin/cpp_clean Build/mod_netcdf.f90
cd Build; pathf95 -c -march=auto -mcpu=auto -mtune=auto -u -m64 -Ofast -freeform mod_netcdf.f90

MODULE mod_netcdf
^
pathf95-855 pathf95: ERROR MOD_NETCDF, File = mod_netcdf.f90, Line = 1, Column = 14
The compiler has detected errors in module "MOD_NETCDF". No module information file will be created for this module.

USE netcdf
^
pathf95-292 pathf95: ERROR MOD_NETCDF, File = mod_netcdf.f90, Line = 19, Column = 13
"NETCDF" is specified as the module name on a USE statement, but the compiler cannot find it.

integer, parameter :: NF_FOUT = nf90_real
^
pathf95-868 pathf95: ERROR MOD_NETCDF, File = mod_netcdf.f90, Line = 21, Column = 41
"NF90_REAL" is used in a constant expression, therefore it must be a constant.

integer, parameter :: NF_FRST = nf90_double
^
pathf95-868 pathf95: ERROR MOD_NETCDF, File = mod_netcdf.f90, Line = 22, Column = 41
"NF90_DOUBLE" is used in a constant expression, therefore it must be a constant.

pathf95: PathScale(TM) Fortran Version 3.1 (f14) Tue Jan 29, 2008 15:50:14
pathf95: 24 source lines
pathf95: 4 Error(s), 0 Warning(s), 0 Other message(s), 0 ANSI(s)
pathf95: "explain pathf95-message number" gives more information about each message
make: *** [Build/mod_netcdf.o] Error 2

Much to my consternation, I haven't been able to hack my way out of this one yet. I previously used version 2.2 of this compiler, and it proved to compile extremely efficient dual-processor code using the OpenMP flag. I've presented the issue to the Pathscale folks as I'm currently using their 30-day trial version and will buy the thing if they can solve the problem.

-----------------------------------------------------------------

ifort 9.1

The official instructions from Intel can be found at:

http://www.intel.com/support/performanc ... 027812.htm

The environment variables that led to success were:

CPPFLAGS=-DpgiFortran
CXX=g++
CXXFLAGS=-O2 -g
CC=gcc
CFLAGS=-O2 -g
FC=/opt/intel/fc/9.1.031/bin/ifort
F90=/opt/intel/fc/9.1.031/bin/ifort
F77=/opt/intel/fc/9.1.031/bin/ifort
FFLAGS=-O2 -g

and the configure/build sequence was:

./configure --prefix=/opt/intel/netcdf-3.6.2
make
su
make install

This one fails during the ROMS compilation with the error message:

ld: skipping incompatible /opt/intel/netcdf-3.6.2/lib/libnetcdf.a when searching for -lnetcdf

and I've not yet figured out why. One of my suspicions is that I might need to compile the C components with the Intel C compilers, but I haven't got those on this platform so I can't check that.

-----------------------------------------------------------------------

gfortran 4.3

I've had no success compiling NetCDF 3.6.2 with this thus far. I'lld add something if and when I do.

Post Reply