Repository: Unidata/netcdf-c
Pull request #2979 (2024-08-14 14:46:56)

added NETCDF_MPIEXEC option to CMake
Fixes https://github.com/Unidata/netcdf-c/issues/2960

Sorry, I accidentally deleted the branch and then had to submit a new PR after restoring it...


Patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a644ef58..960dc043b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -928,6 +928,7 @@ include(cmake/dependencies.cmake)
 set(STATUS_PARALLEL "OFF")
 set(IMPORT_MPI "")
 option(NETCDF_ENABLE_PARALLEL4 "Build netCDF-4 with parallel IO" "${HDF5_PARALLEL}")
+option(NETCDF_MPIEXEC "Command to use instead of mpiexec to launch parallel I/O tests" OFF)
 if(NETCDF_ENABLE_PARALLEL4 AND NETCDF_ENABLE_HDF5)
   if(NOT HDF5_PARALLEL)
     set(USE_PARALLEL OFF CACHE BOOL "")
@@ -937,6 +938,10 @@ if(NETCDF_ENABLE_PARALLEL4 AND NETCDF_ENABLE_HDF5)
     set(USE_PARALLEL ON CACHE BOOL "")
     set(USE_PARALLEL4 ON CACHE BOOL "")
     set(STATUS_PARALLEL "ON")
+    if(NETCDF_MPIEXEC)
+      set(MPIEXEC "${NETCDF_MPIEXEC}")
+    endif()
+    message(STATUS "MPIEXEC command will be ${MPIEXEC}")
     configure_file("${netCDF_SOURCE_DIR}/nc_test4/run_par_test.sh.in"
       "${netCDF_BINARY_DIR}/tmp/run_par_test.sh" @ONLY NEWLINE_STYLE LF)
     file(COPY "${netCDF_BINARY_DIR}/tmp/run_par_test.sh"
@@ -1315,7 +1320,6 @@ CHECK_FUNCTION_EXISTS(_filelengthi64 HAVE_FILE_LENGTH_I64)
 CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
 CHECK_FUNCTION_EXISTS(mremap HAVE_MREMAP)
 CHECK_FUNCTION_EXISTS(fileno HAVE_FILENO)
-CHECK_FUNCTION_EXISTS(H5Literate2 HAVE_H5LITERATE2)
 
 CHECK_FUNCTION_EXISTS(clock_gettime  HAVE_CLOCK_GETTIME)
 CHECK_SYMBOL_EXISTS("struct timespec" "time.h" HAVE_STRUCT_TIMESPEC)
diff --git a/README.md b/README.md
index 3253f6eb6..9f99ded0e 100644
--- a/README.md
+++ b/README.md
@@ -57,9 +57,7 @@ Copyright and licensing information can be found [here](https://www.unidata.ucar
 To install the netCDF-C software, please see the file INSTALL in the
 netCDF-C distribution, or the (usually more up-to-date) document:
 
-* [Building NetCDF with CMake](https://docs.unidata.ucar.edu/netcdf-c/current/netCDF-CMake.html)
-* [Building NetCDF with Autoconf/Automake/Libtool](https://docs.unidata.ucar.edu/netcdf-c/current/netCDF-autotools.html)
-* [Building or Getting Binaries for NetCDF on Windows](https://docs.unidata.ucar.edu/netcdf-c/current/winbin.html)
+* [Building NetCDF](https://docs.unidata.ucar.edu/netcdf-c/current/winbin.html)
 
 ### Documentation
 A language-independent User's Guide for netCDF, and some other
diff --git a/config.h.cmake.in b/config.h.cmake.in
index 3e0bff607..fe7dabcdf 100644
--- a/config.h.cmake.in
+++ b/config.h.cmake.in
@@ -262,9 +262,6 @@ are set when opening a binary file on Windows. */
 /* Define to 1 if you have the `fileno' function. */
 #cmakedefine HAVE_FILENO 1
 
-/* Define to 1 if you have the `H5Literate2' function. */
-#cmakedefine HAVE_H5LITERATE2
-
 /* Define to 1 if you have the `fsync' function. */
 #cmakedefine HAVE_FSYNC 1
 
diff --git a/configure.ac b/configure.ac
index 041b70a4b..290513512 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1618,13 +1618,13 @@ if test "x$enable_hdf5" = xyes; then
    # H5Pset_fapl_mpiposix and H5Pget_fapl_mpiposix have been removed since HDF5 1.8.12.
    # Use H5Pset_fapl_mpio and H5Pget_fapl_mpio, instead.
 
-   AC_CHECK_FUNCS([H5Pget_fapl_mpio H5Pset_deflate H5Z_SZIP H5Pset_all_coll_metadata_ops H5Literate H5Literate2])
+   AC_CHECK_FUNCS([H5Pget_fapl_mpio H5Pset_deflate H5Z_SZIP H5Pset_all_coll_metadata_ops H5Literate])
 
    # Check to see if HDF5 library has collective metadata APIs, (HDF5 >= 1.10.0)
    if test "x$ac_cv_func_H5Pset_all_coll_metadata_ops" = xyes; then
       AC_DEFINE([HDF5_HAS_COLL_METADATA_OPS], [1], [if true, use collective metadata ops in parallel netCDF-4])
    fi
- 
+
    # If parallel is available in hdf5, enable it in the C code. Also add some stuff to netcdf.h.
    if test "x$ac_cv_func_H5Pget_fapl_mpio" = xyes -o "x$ac_cv_func_H5Pget_fapl_mpiposix" = xyes; then
       hdf5_parallel=yes
@@ -2092,20 +2092,11 @@ fi
 
 AC_SUBST(STD_FILTERS,[$std_filters])
 
-# The --with-plugin-dir gives the user control of the plugin
-# directory. If set to 'yes' (the default), then first directory in
-# the HDF5_PLUGIN_PATH, or /usr/local/hdf5/lib/plugin (the default
-# HDF5 plugin dir) will be used. If another directory is provided, it
-# will be used. If 'no', then plugins will not be installed.
+# If user wants, then install selected standard filters
 AC_MSG_CHECKING([whether and where we should install plugins])
-AC_ARG_WITH([plugin-dir], [AS_HELP_STRING([--with-plugin-dir=<absolute directory>|yes|no|--without-plugin-dir],
+AC_ARG_WITH([plugin-dir], [AS_HELP_STRING([--with-plugin-dir=<absolute directory>|no|--without-plugin-dir],
               [Install selected standard filters in specified or default directory])],
 	      [],[with_plugin_dir=no])
-if test "x$have_zstd" = xyes; then
-   if test "x$with_plugin_dir" = xno; then
-      with_plugin_dir=yes
-   fi
-fi
 AC_MSG_RESULT([$with_plugin_dir])
 if test "x$with_plugin_dir" = xno ; then # option missing|disabled
     with_plugin_dir=no
diff --git a/docs/building-with-autotools.md b/docs/building-with-autotools.md
deleted file mode 100644
index 962fd20cb..000000000
--- a/docs/building-with-autotools.md
+++ /dev/null
@@ -1,199 +0,0 @@
-Build Instructions for NetCDF-C using autoconf/automake/libtool {#netCDF-autotools}
-===========================================
-
-[TOC]
-
-# Overview {#autotools_overview}
-
-A CMake build of netCDF is also supported. Users should consider using
-the CMake build, which builds netCDF on a wider range of platforms,
-include Microsoft Windows with Visual Studio. The autotools based
-build may eventually be retired; users may considering transitioning
-to the CMake build. See \ref netCDF-CMake.
-
-We also provide pre-built binary downloads for the shared versions of
-netCDF for use with Visual Studio.
-		
-# Requirements {#autotools_requirements}
-The following packages are required to build netCDF-C.
-
-* netCDF-C Source Code
-* Optional Requirements:
-	* HDF5 Libraries for netCDF4/HDF5 support.
-	* libcurl for DAP support.
-
-<center>
-<img src="deptree.jpg" height="250px" />
-</center>
-
-# The Autotools Build Process {#autotools_build}
-
-There are four steps in the Build Process when using autotools:
-
-1. Configuration: Before compiling, the software is configured based on the desired options.
-2. Building: Once configuration is complete, the libraries are compiled.
-3. Testing: Post-build, it is possible to run tests to ensure the functionality of the netCDF-C libraries.
-4. Installation: If all tests pass, the libraries can be installed in the location specified during configuration.
-
-For users who prefer pre-built binaries, installation packages are available at \ref winbin
-
-## Configuration {#autotools_configuration}
-
-The output of the configuration step are the makefiles which build the library, utilities, and tests.
-
-### Common Configure Options {#autotools_common_options}
-
-| **Option** | **Autotools** | **CMake** |
-| :------- | :---- | :----- |
-Specify Install Location | --prefix=PREFIX | -DCMAKE\_INSTALL\_PREFIX=PREFIX
-Enable/Disable netCDF-4 | --enable-netcdf-4<br>--disable-netcdf-4 | -DENABLE\_NETCDF\_4=ON <br> -DENABLE\_NETCDF\_4=OFF
-Enable/Disable DAP | --enable-dap <br> --disable-dap | -DENABLE\_DAP=ON <br> -DENABLE\_DAP=OFF
-Enable/Disable Utilities | --enable-utilities <br> --disable-utilities | -DBUILD\_UTILITIES=ON <br> -DBUILD\_UTILITIES=OFF
-Specify shared/Static Libraries | --enable-shared <br> --enable-static | -DBUILD\_SHARED\_LIBS=ON <br> -DBUILD\_SHARED\_LIBS=OFF
-Enable/Disable Tests | --enable-testsets <br> --disable-testsets | -DENABLE\_TESTS=ON <br> -DENABLE\_TESTS=OFF
-Specify a custom library location | Use *CFLAGS* and *LDFLAGS* | -DCMAKE\_PREFIX\_PATH=/usr/custom_libs/
-Enable parallel I/O tests | --enable-parallel-tests | -DNETCDF\_ENABLE_PARALLEL\_TESTS=ON
-
-A full list of options can be found by invoking `configure --help`. 
-
-### Configuring your build from the command line. {#autotools_command_line}
-
-The easiest configuration case would be one in which all of the
-dependent libraries are installed on the system path (in either
-Unix/Linux or Windows) and all the default options are desired. In the
-source directory:
-
-> $ ./configure
-
-If you have libraries installed in a custom directory, you will need to
-set the CPPFLAGS and LDFLAGS environment variables to tell the compiler where the
-libraries are installed. For example:
-
-> $ CPPFLAGS=-I/usr/local/hdf5-1.14.3/include LDFLAGS=-L/usr/local/hdf5-1.14.3/lib ./configure --prefix=/usr/local/netcdf-c-4.9.3
-
-#### Building with Parallel I/O. {#autotools_parallel_io}
-
-NetCDF will build with parallel I/O if the C compiler is an MPI
-compiler, and HDF5 was built for parallel I/O. To build netcdf-c for
-parallel I/O, first build HDF5 for parallel I/O, then build netcdf-c
-like this:
-
-> $ CC=mpicc CPPFLAGS=-I/usr/local/hdf5-1.14.3_mpich/include LDFLAGS=-L/usr/local/hdf5-1.14.3_mpicj/lib ./configure --prefix=/usr/local/netcdf-c-4.9.3_mpich --enable-parallel-tests
-
-The parallel I/O tests will only run if the additional configure
-option is used: --enable-parallel-tests. Those tests run (by default)
-with mpiexec, on 4, 16, or 32 processors. If mpiexec cannot be used on
-your login-nodes, a different command can be used to launch the
-parallel I/O tests. Used the --with-mpiexec configure option to set a
-different parallel I/O job launcher:
-
-> $ CC=mpicc CPPFLAGS=-I/usr/local/hdf5-1.14.3_mpich/include LDFLAGS=-L/usr/local/hdf5-1.14.3_mpicj/lib ./configure --prefix=/usr/local/netcdf-c-4.9.3_mpich --enable-parallel-tests --with-mpiexec='srun -A acct_name -q queue_name'
-
-## Setting the HDF5 Plugin Path
-
-Use the --with-plugin-dir= option to set the HDF5 plugin path. This
-path must contain the directory where HDF5 filters have been
-installed. --with-plugin-dir accepts three values:
-
-* yes - use the first directory in environment variable
-HDF5_PLUGIN_PATH (if it is set), or /usr/local/hdf5/lib/plugin (Unix)
-or ${ALLUSERSPROFILE}\\hdfd5\\lib\\plugin (Windows).
-
-* a path - path to be used for plugins.
-
-* no - do not install or use plugins.
-
-## Checking the Configure Summary
-
-At the end of the configure, a summary of the build will be
-output. It's important to check this to ensure that the desired build
-features are accurately set. For example:
-
-<pre>
-# NetCDF C Configuration Summary
-==============================
-
-# General
--------
-NetCDF Version:		4.9.4-development
-Dispatch Version:       5
-Configured On:		Wed Aug  7 06:53:22 MDT 2024
-Host System:		x86_64-pc-linux-gnu
-Build Directory: 	/home/ed/netcdf-c
-Install Prefix:         /usr/local/netcdf-c-4.9.3
-Plugin Install Prefix:  N.A.
-
-# Compiling Options
------------------
-C Compiler:		/usr/bin/gcc
-CFLAGS:			 -fno-strict-aliasing
-CPPFLAGS:		-I/usr/local/hdf5-1.14.3/include
-LDFLAGS:		-L/usr/local/hdf5-1.14.3/lib
-AM_CFLAGS:		
-AM_CPPFLAGS:		
-AM_LDFLAGS:		
-Shared Library:		yes
-Static Library:		yes
-Extra libraries:	-lhdf5_hl -lhdf5 -lm -lz -lsz -lzstd -lxml2 -lcurl 
-XML Parser:             libxml2
-
-# Features
---------
-Benchmarks:		no
-NetCDF-2 API:		yes
-HDF4 Support:		no
-HDF5 Support:		yes
-CDF5 Support:		yes
-NC-4 Parallel Support:	no
-PnetCDF Support:	no
-
-DAP2 Support:		yes
-DAP4 Support:		yes
-Byte-Range Support:	yes
-
-S3 Support:	        no
-S3 SDK:  	        none
-
-NCZarr Support:		yes
-NCZarr Zip Support:     no
-
-Diskless Support:	yes
-MMap Support:		no
-ERANGE Fill Support:	no
-Relaxed Boundary Check:	yes
-
-Quantization:		yes
-Logging:     		no
-SZIP Write Support:     yes
-Standard Filters:       bz2 deflate szip zstd
-ZSTD Support:           yes
-Parallel Filters:       yes
-</pre>
-
-Important settings include:
-* Install Prefix - this is where netCDF will be installed.
-* HDF5 Support - must be 'yes' to use netcdf-4/HDF5 files.
-* NC-4 Parallel Support - Must be 'yes' to use HDF5 parallel I/O.
-* PnetCDF Support - Must be 'yes' to use pnetcdf library for parallel I/O with classic netCDF files.
-* Standard Filters - Must include 'zstd' if zstandard compression is to be used.
-* DAP2/DAP4 Support - Must be 'yes' if OPeNDAP is to be used.
-
-## Building {#autotools_building}
-
-The compiler can be executed directly with 'make'.
-
-> $ make
-
-## Testing {#autotools_testing}
-
-Testing can be executed with:
-
-> $ make check
-
-## Installation {#autotools_installation}
-
-Once netCDF has been built and tested, it may be installed using the following command:
-
-> $ make install
-
-
diff --git a/docs/building-with-cmake.md b/docs/building-with-cmake.md
index a47caa301..3448976b4 100644
--- a/docs/building-with-cmake.md
+++ b/docs/building-with-cmake.md
@@ -5,16 +5,9 @@ Build Instructions for NetCDF-C using CMake {#netCDF-CMake}
 
 # Overview {#cmake_overview}
 
-Starting with netCDF-C 4.3.0, we are happy to announce the inclusion
-of CMake support.  CMake will allow for building netCDF on a wider
-range of platforms, include Microsoft Windows with Visual Studio.
-CMake support also provides robust unit and regression testing tools.
-We will also maintain the standard autotools-based build system in
-parallel.
+Starting with netCDF-C 4.3.0, we are happy to announce the inclusion of CMake support.  CMake will allow for building netCDF on a wider range of platforms, include Microsoft Windows with Visual Studio.  CMake support also provides robust unit and regression testing tools.  We will also maintain the standard autotools-based build system in parallel.
 
-In addition to providing new build options for netCDF-C, we will also
-provide pre-built binary downloads for the shared versions of netCDF
-for use with Visual Studio.
+In addition to providing new build options for netCDF-C, we will also provide pre-built binary downloads for the shared versions of netCDF for use with Visual Studio.  
 
 		
 # Requirements {#cmake_requirements}
@@ -74,24 +67,6 @@ If you have libraries installed in a custom directory, you may need to specify t
 
 > $ cmake [Source Directory] -DCMAKE\_PREFIX\_PATH=/usr/custom_libraries/
 
-#### Building with Parallel I/O. {#cmake_parallel_io}
-
-NetCDF will build with parallel I/O if the C compiler is an MPI
-compiler, and HDF5 was built for parallel I/O. To build netcdf-c for
-parallel I/O, first build HDF5 for parallel I/O, then build netcdf-c
-like this:
-
-> $ CC=mpicc cmake [Source Directory] -DNETCDF\_ENABLE\_PARALLEL_TESTS=ON
-
-The parallel I/O tests will only run if the additional configure
-option is used: NETCDF_ENABLE_PARALLEL_TESTS. Those tests run (by default)
-with mpiexec, on 4, 16, or 32 processors. If mpiexec cannot be used on
-your login-nodes, a different command can be used to launch the
-parallel I/O tests. Used the NETCDF_MPIEXEC option to set a
-different parallel I/O job launcher:
-
-> $ CC=mpicc cmake [Source Directory] -DNETCDF\_ENABLE\_PARALLEL_TESTS=ON -DNETCDF\_MPIEXEC='srun -A account'
-
 ## Building {#cmake_building}
 
 The compiler can be executed directly with 'make' or the appropriate command for the configurator which was used.  
diff --git a/libdispatch/ncuri.c b/libdispatch/ncuri.c
index f22b52ea6..e5be032e4 100644
--- a/libdispatch/ncuri.c
+++ b/libdispatch/ncuri.c
@@ -173,10 +173,7 @@ ncuriparse(const char* uri0, NCURI** durip)
 	2. convert all '\\' -> '\' (Temp hack to remove escape characters
                                     inserted by Windows or MinGW)
     */
-    p = uri;
-    while(*p == ' ') p++;
-    for(q=uri;*p;p++) {if((*p == '\\' && p[1] == '\\')) {continue;} else {*q++ = *p;}}
-    while((q - 1) >= uri && *(q - 1) == ' ') q--;
+    for(q=uri,p=uri;*p;p++) {if((*p == '\\' && p[1] == '\\') || *p < ' ') {continue;} else {*q++ = *p;}}
     *q = '\0';
 
     p = uri;
diff --git a/libhdf5/hdf5open.c b/libhdf5/hdf5open.c
index 082d528a0..c30d4e799 100644
--- a/libhdf5/hdf5open.c
+++ b/libhdf5/hdf5open.c
@@ -2675,7 +2675,7 @@ oinfo_list_add(user_data_t *udata, const hdf5_obj_info_t *oinfo)
  */
 static int
 read_hdf5_obj(hid_t grpid, const char *name,
-#if (defined(H5Lget_info_vers) && H5Lget_info_vers == 2) || defined(HAVE_H5LITERATE2)
+#if defined(H5Lget_info_vers) && H5Lget_info_vers == 2
 	      const H5L_info2_t *info,
 #else
 	      const H5L_info_t *info,
@@ -2857,15 +2857,9 @@ rec_read_metadata(NC_GRP_INFO_T *grp)
      * passed as a parameter to the callback function
      * read_hdf5_obj(). (I have also tried H5Oiterate(), but it is much
      * slower iterating over the same file - Ed.) */
-#ifdef HAVE_H5LITERATE2
-    if (H5Literate2(hdf5_grp->hdf_grpid, iter_index, H5_ITER_INC, &idx,
-                   read_hdf5_obj, (void *)&udata) < 0)
-        BAIL(NC_EHDFERR);
-#else
     if (H5Literate(hdf5_grp->hdf_grpid, iter_index, H5_ITER_INC, &idx,
                    read_hdf5_obj, (void *)&udata) < 0)
         BAIL(NC_EHDFERR);
-#endif
 
     /* Process the child groups found. (Deferred until now, so that the
      * types in the current group get processed and are available for


Test patch:
diff --git a/nczarr_test/Makefile.am b/nczarr_test/Makefile.am
index e868feb57..e6b95d1b5 100644
--- a/nczarr_test/Makefile.am
+++ b/nczarr_test/Makefile.am
@@ -13,10 +13,10 @@ LDADD = ${top_builddir}/liblib/libnetcdf.la
 
 TESTS_ENVIRONMENT =
 TEST_EXTENSIONS = .sh
-#SH_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
-#sh_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
-#LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
-#TESTS_ENVIRONMENT += export SETX=1;
+SH_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
+sh_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
+LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
+TESTS_ENVIRONMENT += export SETX=1;
 #TESTS_ENVIRONMENT += export NCTRACING=1;
 
 AM_CPPFLAGS += -I${top_srcdir} -I${top_srcdir}/libnczarr