Skip to content

Commit

Permalink
Merge pull request #2036 from Unidata/gh1983.wif
Browse files Browse the repository at this point in the history
Address optimization issue
  • Loading branch information
WardF authored Jul 29, 2021
2 parents 0bc8c2e + a89e259 commit 84f0696
Show file tree
Hide file tree
Showing 18 changed files with 397 additions and 148 deletions.
23 changes: 12 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ MACRO(CHECK_C_LINKER_FLAG M_FLAG M_RESULT)
SET(CMAKE_REQUIRED_FLAGS "${T_REQ_FLAG}")
ENDMACRO()

# Enable 'dist and distcheck'.
# File adapted from http://ensc.de/cmake/FindMakeDist.cmake
FIND_PACKAGE(MakeDist)
# End 'enable dist and distcheck'

# Set the build type.
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE DEBUG CACHE STRING "Choose the type of build, options are: None, Debug, Release."
Expand Down Expand Up @@ -199,6 +194,15 @@ ENDIF()

OPTION(NC_FIND_SHARED_LIBS "Find dynamically-built versions of dependent libraries" ${BUILD_SHARED_LIBS})

##
# Check to see if C compiler supports -fno-strict-aliasing, in support of
# https://github.com/Unidata/netcdf-c/issues/1983
##
CHECK_C_COMPILER_FLAG(-fno-strict-aliasing CC_SUPPORTS_NO_STRICT_ALIASING)
IF(CC_SUPPORTS_NO_STRICT_ALIASING)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
ENDIF(CC_SUPPORTS_NO_STRICT_ALIASING)

##
# We've had a request to allow for non-versioned shared libraries.
# This seems reasonable enough to accommodate. See
Expand Down Expand Up @@ -861,7 +865,7 @@ int main() {
}" HAVE_LIBCURL_766)

IF (HAVE_LIBCURL_766)
# If libcurl version is >= 7.66, then can skip tests
# If libcurl version is >= 7.66, then can skip tests
# for these symbols which were added in an earlier version
set(HAVE_CURLOPT_USERNAME TRUE)
set(HAVE_CURLOPT_PASSWORD TRUE)
Expand Down Expand Up @@ -977,9 +981,9 @@ IF(MSVC)
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncdump/)
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/nczarr_test/)
DESTINATION ${netCDF_BINARY_DIR}/nczarr_test/)
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncdap_test/)
DESTINATION ${netCDF_BINARY_DIR}/ncdap_test/)
ENDIF()
ENDIF()

Expand Down Expand Up @@ -2122,9 +2126,6 @@ INSTALL(PROGRAMS ${netCDF_BINARY_DIR}/nc-config
##
print_conf_summary()

# Enable Makedist files.
ADD_MAKEDIST()
ENABLE_MAKEDIST(README.md COPYRIGHT RELEASE_NOTES.md INSTALL INSTALL.cmake test_prog.c lib_flags.am cmake CMakeLists.txt COMPILE.cmake.txt config.h.cmake.in cmake_uninstall.cmake.in netcdf-config-version.cmake.in netcdf-config.cmake.in FixBundle.cmake.in nc-config.cmake.in configure configure.ac install-sh config.h.in config.sub CTestConfig.cmake.in)

#####
# Configure and print the libnetcdf.settings file.
Expand Down
19 changes: 19 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ AC_CANONICAL_TARGET

AC_CONFIG_HEADERS([config.h])


##
# Check to see if the compiler supports -fno-strict-aliasing and, if so,
# add that to the C compiler flags. This is in support of https://github.com/Unidata/netcdf-c/issues/1983.
##
SAVE_CFLAGS="${CFLAGS}"
AC_LANG_PUSH([C])
CFLAGS="${CFLAGS} -fno-strict-aliasing"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
[int i = 0;]])],
[have_no_strict_aliasing=yes],
[have_no_strict_aliasing=no])
AC_MSG_CHECKING([whether compiler supports -fno-strict-aliasing])
AC_MSG_RESULT([$have_no_strict_aliasing])
AC_LANG_POP([C])
if test $have_no_strict_aliasing = no; then
CFLAGS=$SAVE_CFLAGS
fi
##
# Some files need to exist in build directories
# that do not correspond to their source directory, or
Expand Down
11 changes: 7 additions & 4 deletions include/netcdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,14 @@ NOTE: The NC_MAX_DIMS, NC_MAX_ATTRS, and NC_MAX_VARS limits

/** In HDF5 files you can set storage for each variable to be either
* contiguous or chunked, with nc_def_var_chunking(). This define is
* used there. */
* used there. Unknown storage is used for further extensions of HDF5
* storage models, which should be handled transparently by netcdf */
/**@{*/
#define NC_CHUNKED 0
#define NC_CONTIGUOUS 1
#define NC_COMPACT 2
#define NC_CHUNKED 0
#define NC_CONTIGUOUS 1
#define NC_COMPACT 2
#define NC_UNKNOWN_STORAGE 3
#define NC_VIRTUAL 4
/**@}*/

/** In HDF5 files you can set check-summing for each variable.
Expand Down
7 changes: 4 additions & 3 deletions libhdf5/hdf5create.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
}

/* Need this access plist to control how HDF5 handles open objects
* on file close. Setting H5F_CLOSE_SEMI will cause H5Fclose to
* fail if there are any open objects in the file. */
* on file close. (Setting H5F_CLOSE_WEAK will cause H5Fclose not to
* fail if there are any open objects in the file. This may happen when virtual
* datasets are opened). */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0)
BAIL(NC_EHDFERR);
if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_SEMI))
if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_WEAK))
BAIL(NC_EHDFERR);

#ifdef USE_PARALLEL4
Expand Down
17 changes: 14 additions & 3 deletions libhdf5/hdf5open.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,13 @@ nc4_open_file(const char *path, int mode, void* parameters, int ncid)
#endif /* !USE_PARALLEL4 */

/* Need this access plist to control how HDF5 handles open objects
* on file close. (Setting H5F_CLOSE_SEMI will cause H5Fclose to
* fail if there are any open objects in the file). */
* on file close. (Setting H5F_CLOSE_WEAK will cause H5Fclose not to
* fail if there are any open objects in the file. This may happen when virtual
* datasets are opened). */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0)
BAIL(NC_EHDFERR);

if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_SEMI) < 0)
if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_WEAK) < 0)
BAIL(NC_EHDFERR);

#ifdef USE_PARALLEL4
Expand Down Expand Up @@ -1190,6 +1191,16 @@ get_chunking_info(hid_t propid, NC_VAR_INFO_T *var)
{
var->storage = NC_COMPACT;
}
#ifdef H5D_VIRTUAL
else if (layout == H5D_VIRTUAL)
{
var->storage = NC_VIRTUAL;
}
#endif
else
{
var->storage = NC_UNKNOWN_STORAGE;
}

return NC_NOERR;
}
Expand Down
6 changes: 5 additions & 1 deletion libsrc4/nc4internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1694,8 +1694,12 @@ rec_print_metadata(NC_GRP_INFO_T *grp, int tab_count)
strcat(storage_str, "contiguous");
else if (var->storage == NC_COMPACT)
strcat(storage_str, "compact");
else
else if (var->storage == NC_CHUNKED)
strcat(storage_str, "chunked");
else if (var->storage == NC_VIRTUAL)
strcat(storage_str, "virtual");
else
strcat(storage_str, "unknown");
LOG((2, "%s VARIABLE - varid: %d name: %s ndims: %d "
"dimids:%s storage: %s", tabs, var->hdr.id, var->hdr.name,
var->ndims,
Expand Down
2 changes: 1 addition & 1 deletion nc_perf/tst_attsperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ readfile_hdf5(char *file_name, long long *delta, int do_inq, int num_vars)

/* Open and close the root group. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_SEMI)) ERR;
if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_WEAK)) ERR;
if ((hdfid = H5Fopen(file_name, H5F_ACC_RDONLY, fapl_id)) < 0) ERR;
if ((hdf_grpid = H5Gopen2(hdfid, "/", H5P_DEFAULT)) < 0) ERR;

Expand Down
2 changes: 1 addition & 1 deletion nc_test/nc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ main(int argc, char *argv[])
*/
(void) signal(SIGFPE, SIG_IGN);

verbose = 0;
verbose = 1;
max_nmpt = 8;

/* If you uncomment the nc_set_log_level line, you will get a lot
Expand Down
33 changes: 26 additions & 7 deletions nc_test/test_get.m4
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ define(`TEST_NC_GET_VAR1',dnl
int
TestFunc(var1)_$1(VarArgs)
{
int i, err, ncid, cdf_format;
int i=0, err=0, ncid=0, cdf_format=0;
int nok = 0; /* count of valid comparisons */
int canConvert; /* Both text or both numeric */
IntType j, index[MAX_RANK];
double expect;
int canConvert=0; /* Both text or both numeric */
IntType j=0, index[MAX_RANK];
double expect=0;
$1 value[1];

err = FileOpen(testfile, NC_NOWRITE);
Expand Down Expand Up @@ -253,6 +253,10 @@ TestFunc(var)_$1(VarArgs)
double expect[MAX_NELS];
$1 value[MAX_NELS];

for(j = 0; j < MAX_NELS; j++) {
expect[j] = 0;
}

err = FileOpen(testfile, NC_NOWRITE);
IF (err != NC_NOERR) error("open: %s", APIFunc(strerror)(err));

Expand Down Expand Up @@ -376,6 +380,10 @@ TestFunc(vara)_$1(VarArgs)
double expect[MAX_NELS];
$1 value[MAX_NELS];

for(j = 0; j < MAX_NELS; j++) {
expect[j] = 0;
}

err = FileOpen(testfile, NC_NOWRITE);
IF (err != NC_NOERR) error("open: %s", APIFunc(strerror)(err));

Expand Down Expand Up @@ -635,6 +643,10 @@ TestFunc(vars)_$1(VarArgs)
double expect[MAX_NELS];
$1 value[MAX_NELS];

for(j = 0; j < MAX_NELS; j++) {
expect[j] = 0;
}

err = FileOpen(testfile, NC_NOWRITE);
IF (err != NC_NOERR) error("open: %s", APIFunc(strerror)(err));

Expand Down Expand Up @@ -814,7 +826,7 @@ ifelse(`$1',`uchar',`ifdef(`PNETCDF',,``#'endif')')
IF (err != 0) error("error in toMixedBase");
nels = 1;
for (j = 0; j < var_rank[i]; j++) {
count[j] = 1 + (edge[j]-index[j]-1) / (IntType)stride[j];
count[j] = 1 + (edge[j]-index[j]-1) / ( (IntType)stride[j] == 0 ? 1 : (IntType)stride[j]);
nels *= count[j];
index[j] += start[j];
}
Expand Down Expand Up @@ -928,6 +940,10 @@ TestFunc(varm)_$1(VarArgs)
double expect[MAX_NELS];
$1 value[MAX_NELS];

for(j = 0; j < MAX_NELS; j++) {
expect[j] = 0;
}

err = FileOpen(testfile, NC_NOWRITE);
IF (err != NC_NOERR) error("open: %s", APIFunc(strerror)(err));

Expand Down Expand Up @@ -1107,7 +1123,7 @@ ifelse(`$1',`uchar',`ifdef(`PNETCDF',,``#'endif')')
IF (err != 0) error("error in toMixedBase");
nels = 1;
for (j = 0; j < var_rank[i]; j++) {
count[j] = 1 + (edge[j]-index[j]-1) / (IntType)stride[j];
count[j] = 1 + (edge[j]-index[j]-1) / ( (IntType)stride[j] == 0 ? 1 : (IntType)stride[j]);
nels *= count[j];
index[j] += start[j];
}
Expand Down Expand Up @@ -1221,6 +1237,10 @@ TestFunc(att)_$1(AttVarArgs)
double expect[MAX_NELS];
$1 value[MAX_NELS];

for(j = 0; j < MAX_NELS; j++) {
expect[j] = 0;
}

err = FileOpen(testfile, NC_NOWRITE);
IF (err != NC_NOERR) error("open: %s", APIFunc(strerror)(err));

Expand Down Expand Up @@ -1348,4 +1368,3 @@ TEST_NC_GET_ATT(ushort)
TEST_NC_GET_ATT(uint)
TEST_NC_GET_ATT(longlong)
TEST_NC_GET_ATT(ulonglong)

Loading

0 comments on commit 84f0696

Please sign in to comment.