Skip to content

Commit 86e1bf3

Browse files
committed
NetCDF-C version 4.9.0 is required
* NetCDF-4 uses the dimension scale feature which is part of HDF5 high-level APIs, but HDF5 high-level APIs are not well tested for parallel I/O. See Unidata/netcdf-c#2251 and Unidata/netcdf-c#1822 * NetCDF PR #2161 adds a new flag NC_NODIMSCALE_ATTACH to allow users to disable dimension scale, which resolves the problem for e3sm-io. See Unidata/netcdf-c#2161 * NetCDF team indicates PR #2161 will appear in version 4.9.0.
1 parent 2b6b575 commit 86e1bf3

5 files changed

Lines changed: 63 additions & 26 deletions

File tree

INSTALL.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
+ Experimental software developed as part of the Datalib project
1616
* (Optional) [ADIOS 2.7.1](https://github.com/ornladios/ADIOS2/archive/refs/tags/v2.7.1.tar.gz)
1717
+ Configured with parallel I/O support (cmake with `-DADIOS2_USE_MPI=ON` is required)
18-
* (Optional) [NetCDF-C 4.8.1](https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.8.1.tar.gz)
18+
* (Optional) [NetCDF-C 4.9.0](https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.0.tar.gz)
1919
+ Configured with parallel HDF5 support (i.e. `--enable-netcdf4`)
2020
+ Note currently this option fails to run due to a
2121
[bug](https://github.com/Unidata/netcdf-c/issues/2251) in NetCDF-C.
@@ -79,12 +79,12 @@
7979
+ Configure NetCDF-C with parallel HDF5 I/O enabled.
8080
+ Run `make install`
8181
+ Example build commands are given below. This example will install
82-
the NetCDF library under the folder `${HOME}/NetCDF/4.8.1`.
82+
the NetCDF library under the folder `${HOME}/NetCDF/4.9.0`.
8383
```
84-
% wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.8.1.tar.gz
85-
% tar -zxf v4.8.1.tar.gz
86-
% cd netcdf-c-4.8.1
87-
% ./configure --prefix=${HOME}/NetCDF/4.8.1 \
84+
% wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.0.tar.gz
85+
% tar -zxf v4.9.0.tar.gz
86+
% cd netcdf-c-4.9.0
87+
% ./configure --prefix=${HOME}/NetCDF/4.9.0 \
8888
CC=mpicc \
8989
CPPFLAGS=-I${HOME}/HDF5/1.13.0/include \
9090
LDFLAGS=-L${HOME}/HDF5/1.13.0/lib \
@@ -121,6 +121,7 @@
121121
--with-hdf5=${HOME}/HDF5/1.13.0 \
122122
--with-logvol=${HOME}/Log_VOL/1.1.0 \
123123
--with-adios2=${HOME}/ADIOS2/2.7.1 \
124+
--with-netcdf4=${HOME}/NetCDF/4.9.0 \
124125
CC=mpicc CXX=mpicxx
125126
% make
126127
```
@@ -208,13 +209,13 @@
208209
209210
### Current supported APIs (option `-a`) and I/O strategies (option `-x`)
210211
+ Table below lists the supported combinations.
211-
| | pnetcdf | hdf5 | hdf5_log | netcdf4 | adios |
212-
|-----------|:-------:|:----:|:--------:|:-------:|:-----:|
213-
| canonical | yes | yes | no | yes | no |
214-
| log | no | yes | yes | yes* | no |
215-
| blob | yes | yes | no | no | yes |
212+
| | pnetcdf | hdf5 | hdf5_log | netcdf4* | adios |
213+
|-----------|:-------:|:----:|:--------:|:--------:|:-----:|
214+
| canonical | yes | yes | no | yes | no |
215+
| log | no | yes | yes | yes | no |
216+
| blob | yes | yes | no | no | yes |
216217
217-
`*` Requires setting of 2 VOL environment variables. See description below.
218+
`*` NetCDF-C version 4.9.0 or newer is required.
218219
219220
+ **-a pnetcdf -x canonical**
220221
* A single NetCDF file in the classic CDF5 format will be created. All

configure.ac

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ AC_ARG_WITH([netcdf4],
434434
if test "x$netcdf4_config" != x ; then
435435
netcdf4_cflags=`$netcdf4_config --cflags`
436436
netcdf4_lflags=`$netcdf4_config --libs`
437+
netcdf4_version=`$netcdf4_config --version | cut -d' ' -f2 | cut -d'-' -f1`
437438
else
438439
netcdf4_cflags="-I$netcdf4_inc"
439440
netcdf4_lflags="-L$netcdf4_lib"
@@ -454,17 +455,48 @@ AC_ARG_WITH([netcdf4],
454455
LDFLAGS="$LDFLAGS $netcdf4_lflags"
455456
fi
456457
fi
457-
AC_CHECK_HEADER([netcdf.h], [have_netcdf4=yes], [have_netcdf4=no])
458+
AC_CHECK_HEADERS([netcdf.h netcdf_meta.h], [have_netcdf4=yes], [have_netcdf4=no])
458459
if test "x$have_netcdf4" = xno ; then
459460
AC_MSG_WARN([
460461
-----------------------------------------------------------------------
461-
Missing NetCDF-header files 'netcdf4_c.h' required to build E3SM_IO. Use
462-
configure command-line option --with-netcdf4=/path/to/implementation
463-
to specify the location of NetCDF installation. Disable NetCDF 4 support.
462+
Missing NetCDF-header files 'netcdf.h' or 'netcdf_meta.h' which are
463+
required to build E3SM_IO. Use configure command-line option
464+
--with-netcdf4=/path/to/implementation to specify the location of
465+
NetCDF-4 installation. Disable NetCDF-4 support.
464466
-----------------------------------------------------------------------])
465467
fi
466468
467-
AC_MSG_CHECKING([if NetCDF $netcdf_version is configured with parallel I/O enabled])
469+
if test "x$have_netcdf4" = xyes ; then
470+
AC_MSG_CHECKING([NetCDF-C version])
471+
if test "x$netcdf4_version" = x ; then
472+
nc_version_major=`${EGREP} NC_VERSION_MAJOR $netcdf4_inc/netcdf_meta.h| head -1 | cut -d' ' -f3`
473+
nc_version_minor=`${EGREP} NC_VERSION_MINOR $netcdf4_inc/netcdf_meta.h| head -1 | cut -d' ' -f3`
474+
nc_version_patch=`${EGREP} NC_VERSION_PATCH $netcdf4_inc/netcdf_meta.h| head -1 | cut -d' ' -f3`
475+
netcdf4_version="${nc_version_major}.${nc_version_minor}.${nc_version_patch}"
476+
fi
477+
AC_MSG_RESULT([$netcdf4_version])
478+
479+
dnl Check if NetCDF version is 4.9.0 or later
480+
AC_MSG_CHECKING([whether NetCDF-C version is 4.9.0 or later])
481+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
482+
#include <netcdf_meta.h>
483+
#define VER_NUM (NC_VERSION_MAJOR*1000000 + NC_VERSION_MINOR*1000 + NC_VERSION_PATCH)
484+
#if (VER_NUM < 4009000)
485+
#error NetCDF version is older than 4.9.0
486+
#endif
487+
]])], [netcdf_ge_4_9_0=yes], [netcdf_ge_4_9_0=no])
488+
AC_MSG_RESULT([$netcdf_ge_4_9_0])
489+
490+
if test "x${netcdf_ge_4_9_0}" = xno; then
491+
AC_MSG_ERROR([
492+
------------------------------------------------------------
493+
Supplied NetCDF-4 version is $netcdf4_version, but 4.9.0 or later
494+
is required. Abort.
495+
------------------------------------------------------------])
496+
fi
497+
fi
498+
499+
AC_MSG_CHECKING([if NetCDF-4 is configured with parallel I/O enabled])
468500
if test "x$netcdf4_config" != x ; then
469501
netcdf4_has_par=`$netcdf4_config --has-parallel4`
470502
else

src/drivers/e3sm_io_driver_nc4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int e3sm_io_driver_nc4::create (std::string path, MPI_Comm comm, MPI_Info info,
7373
E3SM_IO_TIMER_START (E3SM_IO_TIMER_NC4)
7474
E3SM_IO_TIMER_START (E3SM_IO_TIMER_NC4_OPEN)
7575

76-
err = nc_create_par (path.c_str (), NC_CLOBBER | NC_NETCDF4, comm, info, fid);
76+
err = nc_create_par (path.c_str (), NC_CLOBBER | NC_NETCDF4 | NC_NODIMSCALE_ATTACH, comm, info, fid);
7777
CHECK_NCERR
7878

7979
/* turn off fill mode for the entire file */

test.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ if test "x${ENABLE_ADIOS2}" = x1 ; then
4848
fi
4949

5050
if test "x${ENABLE_NETCDF4}" = x1 ; then
51-
if test "x$#" = x0 ; then :; else
52-
echo "==================================================================="
53-
echo "Warning: skip NetCDF-4 parallel tests due to a bug in NetCDF-C"
54-
echo " version 4.8.1 and prior. See bug issue"
55-
echo " https://github.com/Unidata/netcdf-c/issues/2251"
56-
echo "==================================================================="
57-
fi
5851
APIS+=("netcdf4 canonical")
5952
export LD_LIBRARY_PATH=${HDF5_LIB_PATH}:${NETCDF4_LIB_PATH}:${LD_LIBRARY_PATH}
6053
if test "x${ENABLE_LOGVOL}" = x1 ; then
@@ -107,7 +100,6 @@ for API in "${APIS[@]}" ; do
107100
IN_FILE="${srcdir}/${IN_FILE}.nc"
108101
OUT_FILE+=".nc"
109102
elif test "x${ap[0]}" = xnetcdf4 ; then
110-
if test "x$#" = x0 ; then :; else continue; fi
111103
OUT_FILE+=".nc4"
112104
if test "x${ap[1]}" = xlog ; then
113105
# This option requires the two VOL environment variables to be set.

tests/icase_def.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,31 @@ err = nc_def_dim(ncid, "levdcmp", 15, &dimids[18]); ERR
9393
err = nc_def_dim(ncid, "levtrc", 10, &dimids[19]); ERR
9494
err = nc_def_dim(ncid, "hist_interval", 2, &dimids[20]); ERR
9595

96+
#ifdef DIM_SCALE
9697
err = nc_def_var(ncid, "levgrnd", NC_FLOAT, 1, dimids, &varid); ERR
9798
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 22, "coordinate soil levels"); ERR
9899
err = nc_put_att(ncid, varid, "units", NC_CHAR, 1, "m"); ERR
100+
#endif
99101

102+
#ifdef DIM_SCALE
100103
err = nc_def_var(ncid, "levlak", NC_FLOAT, 1, dimids, &varid); ERR
101104
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 22, "coordinate lake levels"); ERR
102105
err = nc_put_att(ncid, varid, "units", NC_CHAR, 1, "m"); ERR
106+
#endif
103107

108+
#ifdef DIM_SCALE
104109
err = nc_def_var(ncid, "levdcmp", NC_FLOAT, 1, dimids, &varid); ERR
105110
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 22, "coordinate soil levels"); ERR
106111
err = nc_put_att(ncid, varid, "units", NC_CHAR, 1, "m"); ERR
112+
#endif
107113

114+
#ifdef DIM_SCALE
108115
err = nc_def_var(ncid, "time", NC_FLOAT, 1, dimids, &varid); ERR
109116
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 4, "time"); ERR
110117
err = nc_put_att(ncid, varid, "units", NC_CHAR, 30, "days since 0001-01-01 00:00:00"); ERR
111118
err = nc_put_att(ncid, varid, "calendar", NC_CHAR, 6, "noleap"); ERR
112119
err = nc_put_att(ncid, varid, "bounds", NC_CHAR, 11, "time_bounds"); ERR
120+
#endif
113121

114122
err = nc_def_var(ncid, "mcdate", NC_INT, 1, dimids, &varid); ERR
115123
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 23, "current date (YYYYMMDD)"); ERR
@@ -134,17 +142,21 @@ err = nc_def_var(ncid, "date_written", NC_CHAR, 2, dimids, &varid); ERR
134142

135143
err = nc_def_var(ncid, "time_written", NC_CHAR, 2, dimids, &varid); ERR
136144

145+
#ifdef DIM_SCALE
137146
err = nc_def_var(ncid, "lon", NC_FLOAT, 1, dimids, &varid); ERR
138147
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 20, "coordinate longitude"); ERR
139148
err = nc_put_att(ncid, varid, "units", NC_CHAR, 12, "degrees_east"); ERR
140149
err = nc_put_att(ncid, varid, "_FillValue", NC_FLOAT, 1, buf); ERR
141150
err = nc_put_att(ncid, varid, "missing_value", NC_FLOAT, 1, buf); ERR
151+
#endif
142152

153+
#ifdef DIM_SCALE
143154
err = nc_def_var(ncid, "lat", NC_FLOAT, 1, dimids, &varid); ERR
144155
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 19, "coordinate latitude"); ERR
145156
err = nc_put_att(ncid, varid, "units", NC_CHAR, 13, "degrees_north"); ERR
146157
err = nc_put_att(ncid, varid, "_FillValue", NC_FLOAT, 1, buf); ERR
147158
err = nc_put_att(ncid, varid, "missing_value", NC_FLOAT, 1, buf); ERR
159+
#endif
148160

149161
err = nc_def_var(ncid, "area", NC_FLOAT, 2, dimids, &varid); ERR
150162
err = nc_put_att(ncid, varid, "long_name", NC_CHAR, 15, "grid cell areas"); ERR

0 commit comments

Comments
 (0)