Skip to content

Commit

Permalink
Merge pull request #1700 from NCAR/ejh_4_7_2
Browse files Browse the repository at this point in the history
disallow netcdf-c-4.7.2 for both cmake and autotools builds
  • Loading branch information
edwardhartnett authored Aug 7, 2020
2 parents a14b65b + ce1828a commit 9d4dbb7
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 25 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ env:
- LDFLAGS='-L/usr/lib'

script:
- nc-config --all
- autoreconf -i
- export CFLAGS='-std=c99 -fsanitize=address -fno-omit-frame-pointer -Werror'
- export FFLAGS='-fsanitize=address -fno-omit-frame-pointer'
Expand Down
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,35 @@ CHECK_C_SOURCE_COMPILES("
choke me
#endif
int main() {return 0;}" HDF5_HAS_PAR_FILTERS)
if(HDF5_HAS_PAR_FILTERS)
set(HAVE_PAR_FILTERS 1)
else()
set(HAVE_PAR_FILTERS 0)
endif()

###
# Check to see if this is netcdf-c-4.7.2, which won't work.
###
CHECK_C_SOURCE_COMPILES("
#include <netcdf_meta.h>
#if NC_VERSION_MAJOR == 4 && NC_VERSION_MINOR == 7 && NC_VERSION_PATCH == 2
#else
choke me
#endif
int main() {return 0;}" HAVE_472)
if (HAVE_472)
message (FATAL_ERROR "PIO cannot build with netcdf-c-4.7.2, please upgrade your netCDF library")
endif ()

###
# Check to see if dispatch table version 2 is supported for netcdf integration.
###
CHECK_C_SOURCE_COMPILES("
#include <netcdf_meta.h>
#if NC_DISPATCH_VERSION != 2
choke me
#endif
int main() {return 0;}" HAVE_DISPATCH2)

#####
# Configure and print the libpio.settings file.
Expand Down
33 changes: 32 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ AC_DEFINE([_GNU_SOURCE], [1], [solve strnlen declared implicitly warning on inte

# Check for netCDF library.
AC_CHECK_LIB([netcdf], [nc_create], [], [AC_MSG_ERROR([Can't find or link to the netcdf library.])])
AC_CHECK_HEADERS([netcdf.h netcdf_meta.h])

# Check for pnetcdf library.
AC_CHECK_LIB([pnetcdf], [ncmpi_create], [], [])
Expand Down Expand Up @@ -288,14 +289,44 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "netcdf_meta.h"],
AC_MSG_CHECKING([whether netCDF provides szip write capability])
AC_MSG_RESULT([${have_szip_write}])

# Do we have parallel filter support?
# Do we have parallel filter support? Parallel filters are required
# for iotype NETCDF4P to use compression.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "netcdf_meta.h"],
[[#if !NC_HAS_PAR_FILTERS
# error
#endif]
])], [have_par_filters=yes], [have_par_filters=no])
AC_MSG_CHECKING([whether netCDF provides parallel filter support])
AC_MSG_RESULT([${have_par_filters}])
if test "x$have_par_filters" = xyes ; then
AC_DEFINE([HAVE_PAR_FILTERS], [1], [if true, netcdf-c supports filters with parallel I/O])
fi

# Is this version 4.7.2, which does not work?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "netcdf_meta.h"],
[[#if NC_VERSION_MAJOR == 4 && NC_VERSION_MINOR == 7 && NC_VERSION_PATCH == 2
#else
# error
#endif]
])], [have_472=yes], [have_472=no])
AC_MSG_CHECKING([whether this is netcdf-c-4.7.2])
AC_MSG_RESULT([${have_472}])
if test "x$have_472" = xyes; then
AC_MSG_ERROR([PIO cannot build with netcdf-c-4.7.2, please upgrade your netCDF version.])
fi

# Do we have the correct dispatch table version in netcdf-c for netcdf
# integration?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "netcdf_meta.h"],
[[#if NC_DISPATCH_VERSION != 2
# error
#endif]
])], [have_dispatch2=yes], [have_dispatch2=no])
AC_MSG_CHECKING([whether netcdf-c supports version 2 of dispatch table for netcdf integration])
AC_MSG_RESULT([${have_dispatch2}])
if test "x$enable_netcdf_integration" = xyes -a "x$have_dispatch2" = xno; then
AC_MSG_ERROR([NetCDF integration cannot be used with this version of netcdf-c, please upgrade your netCDF version.])
fi

# Set some build settings for when netcdf-4 is supported.
if test x$have_netcdf_par = xyes; then
Expand Down
26 changes: 22 additions & 4 deletions tests/cunit/test_pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1570,9 +1570,19 @@ int test_nc4(int iosysid, int num_flavors, int *flavor, int my_rank)
if ((ret = PIOc_def_var_chunking(ncid, 0, NC_CHUNKED, chunksize)))
ERR(ret);

/* Setting deflate works with parallel iotype starting with netcdf-c-4.7.4. */
if ((ret = PIOc_def_var_deflate(ncid, 0, 0, 1, 1)))
/* Setting deflate works with parallel iotype starting
* with netcdf-c-4.7.4. If present, HAVE_PAR_FILTERS will
* be defined. */
ret = PIOc_def_var_deflate(ncid, 0, 0, 1, 1);
#ifdef HAVE_PAR_FILTERS
if (ret)
ERR(ret);
#else
if (flavor[fmt] == PIO_IOTYPE_NETCDF4C && ret)
ERR(ret);
if (flavor[fmt] == PIO_IOTYPE_NETCDF4P && !ret)
ERR(ERR_WRONG);
#endif

/* Check that the inq_varname function works. */
if ((ret = PIOc_inq_varname(ncid, 0, NULL)))
Expand Down Expand Up @@ -1602,10 +1612,18 @@ int test_nc4(int iosysid, int num_flavors, int *flavor, int my_rank)
if (shuffle || !deflate || deflate_level != 1)
ERR(ERR_AWFUL);

/* For parallel netCDF-4, we turned on deflate above. */
/* For parallel netCDF-4, we turned on deflate above, if
* HAVE_PAR_FILTERS is defined. */
if (flavor[fmt] == PIO_IOTYPE_NETCDF4P)
if (shuffle || !deflate || deflate_level != 1)
{
#ifdef HAVE_PAR_FILTERS
if (shuffle || !deflate || deflate_level != 1)
ERR(ERR_AWFUL);
#else
if (shuffle || deflate)
ERR(ERR_AWFUL);
#endif /* HAVE_PAR_FILTERS */
}

/* Check setting the chunk cache for the variable. */
if ((ret = PIOc_set_var_chunk_cache(ncid, 0, VAR_CACHE_SIZE, VAR_CACHE_NELEMS,
Expand Down
56 changes: 36 additions & 20 deletions tests/unit/ncdf_tests.F90
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,19 @@ Subroutine test_nc4(test_id, err_msg)
ret_val = PIO_def_var_deflate(pio_file, pio_var, shuffle, deflate, &
deflate_level)

! Should not have worked except for netCDF-4/HDF5.
if ((iotype .eq. PIO_iotype_netcdf4c .or. iotype .eq. PIO_iotype_netcdf4p) &
.and. ret_val .ne. PIO_NOERR) then
! Should not have worked except for netCDF-4/HDF5 sequential, and
! perhaps parallel.
if (iotype .eq. PIO_iotype_netcdf4c .and. ret_val .ne. PIO_NOERR) then
err_msg = "Could not turn on compression for variable foo2222"
call PIO_closefile(pio_file)
return
else if (iotype .eq. PIO_iotype_netcdf4p) then
!err_msg = "Could not turn on compression for variable foo2222"
! if (ret_val .ne. PIO_NOERR) then
! call PIO_closefile(pio_file)
! return
! end if
! return
else if (iotype .eq. PIO_iotype_pnetcdf .and. ret_val .eq. PIO_NOERR) then
err_msg = "Did not get expected error when trying to turn deflate on for pnetcdf file"
call PIO_closefile(pio_file)
Expand Down Expand Up @@ -510,8 +517,8 @@ Subroutine test_nc4(test_id, err_msg)
print*, 'testing PIO_inq_var_deflate'
ret_val = PIO_inq_var_deflate(pio_file, pio_var, shuffle, deflate, my_deflate_level)

! Should not have worked except for netCDF-4/HDF5.
if (iotype .eq. PIO_iotype_netcdf4c .or. iotype .eq. PIO_iotype_netcdf4p) then
! Should not have worked except for netCDF-4/HDF5 sequential, and maybe parallel.
if (iotype .eq. PIO_iotype_netcdf4c) then
if (ret_val .ne. PIO_NOERR) then
err_msg = "Got error trying to inquire about deflate on for serial netcdf-4 file"
call PIO_closefile(pio_file)
Expand All @@ -524,6 +531,15 @@ Subroutine test_nc4(test_id, err_msg)
return
end if
end if
else if (iotype .eq. PIO_iotype_netcdf4p) then
! if (ret_val .eq. PIO_NOERR) then
! print *,shuffle, deflate, deflate_level, my_deflate_level
! if (shuffle .ne. 0 .or. deflate .ne. 1 .or. my_deflate_level .ne. deflate_level) then
! err_msg = "Wrong values for deflate and shuffle for parallel netcdf-4 file"
! call PIO_closefile(pio_file)
! return
! end if
! end if
else if ((iotype .eq. PIO_iotype_pnetcdf .or. iotype .eq. PIO_iotype_netcdf) .and. ret_val .eq. PIO_NOERR) then
err_msg = "Did not get expected error when trying to check deflate for non-netcdf-4 file"
call PIO_closefile(pio_file)
Expand All @@ -548,10 +564,10 @@ Subroutine test_nc4(test_id, err_msg)
err_msg = "Did not get expected error when trying to turn deflate on for netcdf classic file"
call PIO_closefile(pio_file)
return
else if (iotype .eq. PIO_iotype_netcdf4p .and. ret_val .ne. PIO_NOERR) then
err_msg = "Could not turn on compression for variable foo2222 second time"
call PIO_closefile(pio_file)
return
else if (iotype .eq. PIO_iotype_netcdf4p) then
! err_msg = "Could not turn on compression for variable foo2222 second time"
! call PIO_closefile(pio_file)
! return
end if

! Leave define mode
Expand Down Expand Up @@ -584,17 +600,17 @@ Subroutine test_nc4(test_id, err_msg)
call PIO_closefile(pio_file)
return
else if (iotype .eq. PIO_iotype_netcdf4p) then
if (ret_val .ne. PIO_NOERR) then
err_msg = "Got error trying to inquire about deflate on for parallel netcdf-4 file"
call PIO_closefile(pio_file)
return
else
if (shuffle .ne. 0 .or. deflate .ne. 1 .or. my_deflate_level .ne. deflate_level_2) then
err_msg = "Wrong values for deflate and shuffle for parallel netcdf-4 file"
call PIO_closefile(pio_file)
return
end if
end if
! if (ret_val .ne. PIO_NOERR) then
! err_msg = "Got error trying to inquire about deflate on for parallel netcdf-4 file"
! call PIO_closefile(pio_file)
! return
! else
! if (shuffle .ne. 0 .or. deflate .ne. 1 .or. my_deflate_level .ne. deflate_level_2) then
! err_msg = "Wrong values for deflate and shuffle for parallel netcdf-4 file"
! call PIO_closefile(pio_file)
! return
! end if
! end if
end if

! Write foo2
Expand Down

0 comments on commit 9d4dbb7

Please sign in to comment.