PGI Guide to NetCDF

This guide is intended to help build and test the network Common Data Format libraries using the PGI 2012 compilers.

Version Information

This guide was created for the 4.1.1 release of netCDF and PGI 2012 release. This information is for both x64 processors running 64-bit Linux or Mac OS X and x86 processors running 32-bit Linux or Mac OS X.

Application Notes

Information about netCDF can be found at the netCDF FAQ page.

(From the webpage) "NetCDF (network Common Data Form) is an interface for array-oriented data access and a freely-distributed collection of software libraries for C, Fortran, C++, Java, and perl that provide implementations of the interface. The netCDF software was developed by Glenn Davis, Russ Rew, Steve Emmerson, John Caron, and Harvey Davies at the Unidata Program Center in Boulder, Colorado, and augmented by contributions from other netCDF users. The netCDF libraries define a machine-independent format for representing scientific data. Together, the interface, libraries, and format support the creation, access, and sharing of scientific data."

Obtaining the Source Code

netCDF source code can be downloaded from anonymous FTP found at the netCDF FTP site or on the web at the netCDF FAQ page. The 4.0 release notes contain information about this release.



Building netCDF and Testing

  1. Untar the netCDF package:

    tar -xvzf netcdf-4.1.1.tar.gz
    cd netcdf-4.1.1
  2. Edit the file configure and change line 15387 from:

    *pgCC\ [1-5]* | *pgcpp\ [1-5]*)


    *pgCC\ [1-5].* | *pgcpp\ [1-5].*)

    These changes will allow the match for the PGI 2010 release 10.0 and above compilers to fall through to a lower stanza rather than matching a stanza intended for PGI compilers prior to Release 6.0.

  3. Set up your environment:

    NetCDF 4.x depends on HDF5. You will need to compile HDF5 and install it before configuring and building NetCDF. You will need to use the same compiler commands to build NetCDF as you used to build HDF5. Most likely, you built the parallel version of HDF5 using MPI compilers. You'll need to use the same compilers to build NetCDF. If you only compiled HDF5 for serial mode by invoking the PGI compilers directly, use those same compilers name to build NetCDF. If you don't need any HDF5 functionality, you can use the PGI compilers directly and supply the --disable-netcdf-4 flag to configure as noted below.

    If you used MPI compilers to build HDF5, then use the same compilers to build NetCDF:

    setenv CC mpicc
    setenv CXX mpicxx
    setenv FC mpif90
    setenv F90 mpif90
    setenv LD mpif90
    setenv CPPFLAGS "-DpgiFortran"

    If you built HDF5 invoking the PGI compilers directly, then also invoke them directly for NetCDF:

    setenv CC pgcc
    setenv CXX pgcpp
    setenv FC pgfortran
    setenv F90 pgfortran
    setenv LD pgfortran
    setenv CPPFLAGS "-DpgiFortran"
  4. Configure the source code:

    ./configure --prefix=/usr/local >& config.log
  5. Build the code:

    make >& make.log
  6. Test the build:

    make test >& make_test.log
  7. Finally, install the results:

    sudo make install

Note the example above uses the csh command setenv to set the environment variables. Please change this to match your shell's method of setting environment variables.

The exact optimizations you use should be adjusted depending upon how you compile the applications that will use the netCDF library. If your application is 32-bits and is compiled with ‑Mcache_align or the aggregate flag ‑fastsse which contains ‑Mcache_align, then you must add ‑Mcache_align or ‑fastsse to the CFLAGS and FFLAGS. Failure to do so may result in a segmentation violation cause by mismatched data alignment.

Known Issues

  1. -bind_at_load

    The netCDF build scripts use ‑bind_at_load which can cause PGI compilers to react poorly. To work around this problem, create or edit a siterc file with these contents:

    switch -bind_at_load is replace(-bind_at_load) positional(linker);

    Place (or find) the file in $PGI/linux86/2012/bin/siterc and $PGI/linux86-64/2012/bin/siterc or in $PGI/osx86/2012/bin/siterc and $PGI/osx86-64/2012/bin/siterc

  2. Missing 32-bit header files

    If the configuration fails with the following error:

    checking whether we are cross compiling... configure: error: in
    configure: error: cannot run C compiled programs.
    If you meant to cross compile, use `--host'.
    See `config.log' for more details

    The cause is likely you're building on a 64-bit machine. NetCDF requires some 32-bit header files. To install them, enter:

    sudo apt-get install libc6-dev-i386

    Once this package is installed, the configure should proceed without error.

  3. HDF5

    NetCDF 4.x requires HDF5. To build without having HDF5 installed, use this command:

    ./configure --prefix=/user/local --disable-netcdf-4
Click me