Tuesday, June 01, 2021

Build NetCDF (includes HDF5, szip) with AMD AOCC 3.0.0 on CentOS 7

The AOCC is based on LLVM 12, so the problem rises from the clang / flang support with the libraries.

The test here was done on CentOS 7.9, with AOCC 3.0.0, szip 2.1.1, HDF5 1.12.0, NetCDF-C 4.8.0 and NetCDF-Fortran 4.5.3. Also, a copy of cmake 3.20.3 was built from source with built-in gcc 4.8.5.

These libraries will be installed to the same folder, $NETCDF.

Remember to setup the AOCC by sourcing the setenv_AOCC.sh, and set the PATH and LD_LIBRARY_PATH to $NETCDF/bin and $NETCDF/lib.

1. The szip can be built (static and shared) with configure method without problem:

./configure --prefix=$NETCDF CC=clang; make -j4; make install

2. The HDF5 shared Fortran library can't be built with configure method, for the libtool lacks flang support. If you need static C / Fortran library only , or need shared C library only, you can get away with configure method:

./configure --prefix=$NETCDF --with-szlib=$NETCDF \
--enable-build-mode=production --with-szlib=$NETCDF \
--with-default-api-version=v18 --enable-shared=no \
--enable-fortran=yes CC=clang FC=flang; \
make -j4; make install

or:

./configure --prefix=$NETCDF --with-szlib=$NETCDF \
--enable-build-mode=production --with-szlib=$NETCDF \
--with-default-api-version=v18 --enable-shared=yes \
--enable-fortran=no CC=clang; make -j4; make install

If you do need the HDF5 shared Fortran library built, you'll have to build it with cmake:

mkdir build; cd build; cmake .. -DCMAKE_INSTALL_PREFIX=$NETCDF \
-DCMAKE_C_COMPILER=clang -DCMAKE_Fortran_COMPILER=flang \
-DSZIP_LIBRARY=$NETCDF/lib/libsz.so -SZIP_INCLUDE_DIR=$NETCDF/include \
-DSZIP_USE_EXTERNAL:BOOL=OFF -DZLIB_LIBRARY=/usr/lib64/libz.so \
-DZLIB_INCLUDE_DIR=/usr/include -DZLIB_USE_EXTERNAL:BOOL=OFF \
-DHDF5_BUILD_FORTRAN=ON -DHDF5_ENABLE_SZIP_SUPPORT=ON \
-DHDF5_ENABLE_Z_LIB_SUPPORT=ON -DDEFAULT_API_VERSION=v18 \
-DCMAKE_BUILD_TYPE=Release; make -j4; make install

3. The NetCDF-C can be built with configure method without problem:

./configure --prefix=$NETCDF CPPFLAGS=-I$NETCDF/include \
LDFLAGS=-L$NETCDF/lib CC=clang; make -j4; make install

4. Again, you can get away with configure if you need static NetCDF-Fortran library only:

./configure --prefix=$NETCDF CPPFLAGS=-I$NETCDF/include \
LDFLAGS=-L$NETCDF/lib CC=clang FC=flang F77=flang --enable-shared=no; \
make -j4; make install

But you'll have to use cmake to build shared NetCDF-Fortran library:

mkdir build; cd build; cmake .. -DCMAKE_C_COMPILER=clang \
-DCMAKE_INSTALL_PREFIX=$NETCDF -DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_Fortran_COMPILER=flang -DHAVE_SZIP_WRITE=1; \
make -j4; make install

Note that the cmake in NetCDF-Fortran can only build shared library. So if you need both the static and shared libraries, you'll have to it twice.

The resulting libraries can be used to build WRF-ARW 4.2.1, with modified configure.wrf from option 54 (PGI clang/flang dmpar) template. The WRF can run single domain case without error. The WRF is another topic and will not be mentioned here.

No comments:

Post a Comment