diff --git a/CMakeVOL.cmake b/CMakeVOL.cmake index 79afa59a2fb..8b2207ae1dc 100644 --- a/CMakeVOL.cmake +++ b/CMakeVOL.cmake @@ -26,14 +26,51 @@ function (get_generated_cmake_targets out_var dir) set (${out_var} "${dir_targets}" PARENT_SCOPE) endfunction () -# For now, only support building of external VOL connectors with FetchContent -option (HDF5_VOL_ALLOW_EXTERNAL "Allow building of external HDF5 VOL connectors with FetchContent" "NO") -mark_as_advanced (HDF5_VOL_ALLOW_EXTERNAL) -if (HDF5_VOL_ALLOW_EXTERNAL) - if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "NO" OR (NOT HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT" AND NOT HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR")) - message (FATAL_ERROR "HDF5_VOL_ALLOW_EXTERNAL must be set to 'GIT' or 'LOCAL_DIR' to allow building of external HDF5 VOL connectors") - endif() +# Function to apply connector-specify workarounds to build +# code once a connector has been populated through FetchContent +function (apply_connector_workarounds connector_name source_dir) + # For the cache VOL, remove the call to find_package(ASYNC). + # Eventually, the FetchContent OVERRIDE_FIND_PACKAGE should be + # able to fulfill this dependency when building the cache VOL, + # but for now we have to hack around this until the async and + # cache VOLs create CMake .config files + if ("${connector_name}" MATCHES "vol-cache") + # Remove find_package(ASYNC) call from connector's CMake code + file (READ "${source_dir}/CMakeLists.txt" vol_cmake_contents) + string (REGEX REPLACE "[ \t]*find_package[ \t]*\\([ \t]*ASYNC[^\r\n\\)]*\\)[ \t]*[\r\n]+" "" vol_cmake_contents "${vol_cmake_contents}") + file (WRITE "${source_dir}/CMakeLists.txt" "${vol_cmake_contents}") + + # Remove setting of HDF5_VOL_CONNECTOR and HDF5_PLUGIN_PATH + # in connector's external tests CMake code + file (STRINGS "${source_dir}/tests/CMakeLists.txt" file_lines) + file (WRITE "${source_dir}/tests/CMakeLists.txt" "") + foreach (line IN LISTS file_lines) + set (stripped_line "${line}") + string (REGEX MATCH "^[ \t]*set_tests_properties\\([ \t]*[\r\n]?" match_string "${line}") + if (NOT "${match_string}" STREQUAL "") + string (REGEX REPLACE "^[ \t]*set_tests_properties\\([ \t]*[\r\n]?" "" stripped_line "${line}") + endif () + string (REGEX MATCH "^[ \t]*.\\{test\\}[ \t]*[\r\n]?" match_string "${line}") + if (NOT "${match_string}" STREQUAL "") + string (REGEX REPLACE "^[ \t]*.\\{[A-Za-z]*\\}[ \t]*[\r\n]?" "" stripped_line "${line}") + endif () + string (REGEX MATCH "^[ \t]*PROPERTIES[ \t]*[\r\n]?" match_string "${line}") + if (NOT "${match_string}" STREQUAL "") + string (REGEX REPLACE "^[ \t]*PROPERTIES[ \t]*[\r\n]?" "" stripped_line "${line}") + endif () + string (REGEX MATCH "^[ \t]*ENVIRONMENT[ \t]*.*[\r\n]?" match_string "${line}") + if (NOT "${match_string}" STREQUAL "") + string (REGEX REPLACE "^[ \t]*ENVIRONMENT[ \t]*.*[\r\n]?" "" stripped_line "${line}") + endif () + file (APPEND "${source_dir}/tests/CMakeLists.txt" "${stripped_line}\n") + endforeach () + endif () +endfunction () +set (HDF5_VOL_ALLOW_EXTERNAL "NO" CACHE STRING "Allow building of external HDF5 VOL connectors with FetchContent") +set_property (CACHE HDF5_VOL_ALLOW_EXTERNAL PROPERTY STRINGS NO GIT LOCAL_DIR) +mark_as_advanced (HDF5_VOL_ALLOW_EXTERNAL) +if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT" OR HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") # For compatibility, set some variables that projects would # typically look for after calling find_package(HDF5) set (HDF5_FOUND 1) @@ -103,6 +140,13 @@ if (HDF5_VOL_ALLOW_EXTERNAL) mark_as_advanced ("HDF5_VOL_${hdf5_vol_name_upper}_BRANCH") endif() + set ("HDF5_VOL_${hdf5_vol_name_upper}_CMAKE_PACKAGE_NAME" + "${hdf5_vol_name_lower}" + CACHE + STRING + "CMake package name used by find_package(...) calls for VOL connector '${hdf5_vol_name}'" + ) + set ("HDF5_VOL_${hdf5_vol_name_upper}_NAME" "" CACHE STRING "Name of VOL connector to set for the HDF5_VOL_CONNECTOR environment variable") option ("HDF5_VOL_${hdf5_vol_name_upper}_TEST_PARALLEL" "Whether to test VOL connector '${hdf5_vol_name}' against the parallel API tests" OFF) @@ -124,22 +168,40 @@ if (HDF5_VOL_ALLOW_EXTERNAL) message (FATAL_ERROR "HDF5_VOL_PATH${vol_idx_fixed} must be an absolute path to a valid directory") endif () + # Set internal convenience variables for FetchContent dependency name + set (hdf5_vol_depname "${HDF5_VOL_${hdf5_vol_name_upper}_CMAKE_PACKAGE_NAME}") + string (TOLOWER "${hdf5_vol_depname}" hdf5_vol_depname_lower) + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") - FetchContent_Declare (HDF5_VOL_${hdf5_vol_name_lower} - GIT_REPOSITORY "${HDF5_VOL_SOURCE}" - GIT_TAG "${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}" - ) + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") + FetchContent_Declare (${hdf5_vol_depname} + GIT_REPOSITORY "${HDF5_VOL_SOURCE}" + GIT_TAG "${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}" + OVERRIDE_FIND_PACKAGE + ) + else () + FetchContent_Declare (${hdf5_vol_depname} + GIT_REPOSITORY "${HDF5_VOL_SOURCE}" + GIT_TAG "${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}" + FIND_PACKAGE_ARGS NAMES ${hdf5_vol_name_lower} + ) + endif () elseif(HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") - FetchContent_Declare (HDF5_VOL_${hdf5_vol_name_lower} - SOURCE_DIR "${HDF5_VOL_SOURCE}" + FetchContent_Declare (${hdf5_vol_depname} + SOURCE_DIR "${HDF5_VOL_SOURCE}" ) endif() - FetchContent_GetProperties(HDF5_VOL_${hdf5_vol_name_lower}) - if (NOT hdf5_vol_${hdf5_vol_name_lower}_POPULATED) - FetchContent_Populate(HDF5_VOL_${hdf5_vol_name_lower}) + FetchContent_GetProperties(${hdf5_vol_depname}) + if (NOT ${hdf5_vol_depname}_POPULATED) + FetchContent_Populate(${hdf5_vol_depname}) + + # Now that content has been populated, set other internal + # convenience variables for FetchContent dependency + set (hdf5_vol_depname_source_dir "${${hdf5_vol_depname_lower}_SOURCE_DIR}") + set (hdf5_vol_depname_binary_dir "${${hdf5_vol_depname_lower}_BINARY_DIR}") - if (NOT EXISTS "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/CMakeLists.txt") + if (NOT EXISTS "${hdf5_vol_depname_source_dir}/CMakeLists.txt") if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") message (SEND_ERROR "The git repository branch '${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}' for VOL connector '${hdf5_vol_name}' does not appear to contain a CMakeLists.txt file") elseif (HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") @@ -150,21 +212,24 @@ if (HDF5_VOL_ALLOW_EXTERNAL) # If there are any calls to find_package(HDF5) in the connector's # CMakeLists.txt files, remove those since any found HDF5 targets # will conflict with targets being generated by this build of HDF5 - if (EXISTS "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/CMakeLists.txt") - file (READ "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/CMakeLists.txt" vol_cmake_contents) + if (EXISTS "${hdf5_vol_depname_source_dir}/CMakeLists.txt") + file (READ "${hdf5_vol_depname_source_dir}/CMakeLists.txt" vol_cmake_contents) string (REGEX REPLACE "[ \t]*find_package[ \t]*\\([ \t]*HDF5[^\r\n\\)]*\\)[ \t]*[\r\n]+" "" vol_cmake_contents "${vol_cmake_contents}") - file (WRITE "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/CMakeLists.txt" "${vol_cmake_contents}") + file (WRITE "${hdf5_vol_depname_source_dir}/CMakeLists.txt" "${vol_cmake_contents}") endif () - if (EXISTS "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/src/CMakeLists.txt") - file (READ "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/src/CMakeLists.txt" vol_cmake_contents) + if (EXISTS "${hdf5_vol_depname_source_dir}/src/CMakeLists.txt") + file (READ "${hdf5_vol_depname_source_dir}/src/CMakeLists.txt" vol_cmake_contents) string (REGEX REPLACE "[ \t]*find_package[ \t]*\\([ \t]*HDF5[^\r\n\\)]*\\)[ \t]*[\r\n]+" "" vol_cmake_contents "${vol_cmake_contents}") - file (WRITE "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/src/CMakeLists.txt" "${vol_cmake_contents}") + file (WRITE "${hdf5_vol_depname_source_dir}/src/CMakeLists.txt" "${vol_cmake_contents}") endif () - add_subdirectory (${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR} ${hdf5_vol_${hdf5_vol_name_lower}_BINARY_DIR}) + # Apply any connector-specific workarounds + apply_connector_workarounds ("${hdf5_vol_name_lower}" "${hdf5_vol_depname_source_dir}") + + add_subdirectory (${hdf5_vol_depname_source_dir} ${hdf5_vol_depname_binary_dir}) # Get list of targets generated by build of connector - get_generated_cmake_targets (connector_targets ${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}) + get_generated_cmake_targets (connector_targets ${hdf5_vol_depname_source_dir}) # Create a custom target for the connector to encompass all its # targets and other custom properties set by us for later use @@ -217,8 +282,30 @@ if (HDF5_VOL_ALLOW_EXTERNAL) HDF5_VOL_TEST_PARALLEL ${HDF5_VOL_${hdf5_vol_name_upper}_TEST_PARALLEL} ) - # Add this connector's target to the list of external connector targets + # Add this VOL connector's target to the list of external connector targets list (APPEND HDF5_EXTERNAL_VOL_TARGETS "HDF5_VOL_${hdf5_vol_name_lower}") + + # Get the list of library targets from this VOL connector + unset (connector_lib_targets) + foreach (connector_target ${connector_targets}) + get_target_property (target_type ${connector_target} TYPE) + if (target_type STREQUAL "SHARED_LIBRARY" OR target_type STREQUAL "STATIC_LIBRARY") + list (APPEND connector_lib_targets "${connector_target}") + endif () + endforeach () + + # Add all of the previous VOL connector's library targets as + # dependencies for the current VOL connector to ensure that + # VOL connectors get built serially in case there are dependencies + if (DEFINED last_vol_lib_targets) + foreach (connector_target ${connector_targets}) + add_dependencies (${connector_target} ${last_vol_lib_targets}) + endforeach () + endif () + + # Use this connector's library targets as dependencies + # for the next connector that is built + set (last_vol_lib_targets "${connector_lib_targets}") endif () endif () endforeach () diff --git a/doc/cmake-vols-fetchcontent.md b/doc/cmake-vols-fetchcontent.md index 9d3c1ba85ac..ff0591311c4 100644 --- a/doc/cmake-vols-fetchcontent.md +++ b/doc/cmake-vols-fetchcontent.md @@ -97,12 +97,21 @@ After the VOL's internal name is generated, the following new variables get crea variable must be set in order for the VOL connector to be testable with HDF5's tests. + HDF5_VOL__CMAKE_PACKAGE_NAME (Default: ">") + This variable specifies the exact name that would be passed to CMake + find_package(...) calls for the VOL connector in question. It is used as + the dependency name when making CMake FetchContent calls to try to ensure + that any other VOL connectors to be built which depend on this VOL connector + can make find_package(...) calls for this VOL connector at configure time. + By default, this variable is set to a lowercased version of the internal + name generated for the VOL connector (described above). + HDF5_VOL__TEST_PARALLEL (Default: OFF) This variable determines whether the VOL connector with the CMake-internal name '' should be tested against HDF5's parallel tests. If the source was retrieved from a Git URL, then the following variable will additionally be created: - + HDF5_VOL__BRANCH (Default: "main") This variable specifies the git branch name or tag to use when fetching the source code for the VOL connector with the CMake-internal name @@ -111,9 +120,10 @@ If the source was retrieved from a Git URL, then the following variable will add As an example, this would create the following variables for the previously-mentioned VOL connector if it is retrieved from a URL: - HDF5_VOL_VOL-ASYNC_BRANCH - HDF5_VOL_VOL-ASYNC_NAME - HDF5_VOL_VOL-ASYNC_TEST_PARALLEL + HDF5_VOL_VOL-ASYNC_NAME "" + HDF5_VOL_VOL-ASYNC_CMAKE_PACKAGE_NAME "vol-async" + HDF5_VOL_VOL-ASYNC_BRANCH "main" + HDF5_VOL_VOL-ASYNC_TEST_PARALLEL OFF **NOTE** If a VOL connector requires extra information to be passed in its @@ -139,9 +149,10 @@ would typically be passed when building HDF5, such as `CMAKE_INSTALL_PREFIX`, -DHDF5_TEST_API=ON -DHDF5_VOL_ALLOW_EXTERNAL="GIT" -DHDF5_VOL_URL01=https://github.com/hpc-io/vol-async.git - -DHDF5_VOL_VOL-ASYNC_BRANCH=develop + -DHDF5_VOL_VOL-ASYNC_BRANCH=develop -DHDF5_VOL_VOL-ASYNC_NAME="async under_vol=0\;under_info={}" - -DHDF5_VOL_VOL-ASYNC_TEST_PARALLEL=ON .. + -DHDF5_VOL_VOL-ASYNC_TEST_PARALLEL=ON + .. Here, we are specifying that: @@ -156,7 +167,8 @@ Here, we are specifying that: variable should be set to "async under_vol=0\;under_info={}", which specifies that the VOL connector with the canonical name "async" should be loaded and it should be passed the string "under_vol=0;under_info={}" - for its configuration + for its configuration (note the backslash-escaping of semicolons in the string + provided) * The Asynchronous I/O VOL connector should be tested against HDF5's parallel API tests Note that this also assumes that the Asynchronous I/O VOL connector's diff --git a/test/API/CMakeLists.txt b/test/API/CMakeLists.txt index e90a4c8985e..e8220eaa672 100644 --- a/test/API/CMakeLists.txt +++ b/test/API/CMakeLists.txt @@ -134,7 +134,7 @@ target_compile_options ( target_compile_definitions ( h5_api_test PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" + "${HDF5_TEST_COMPILE_DEFS_PRIVATE}" ) if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (h5_api_test STATIC) diff --git a/test/API/H5_api_test.c b/test/API/H5_api_test.c index 654eb4024ac..ff7ede34038 100644 --- a/test/API/H5_api_test.c +++ b/test/API/H5_api_test.c @@ -136,15 +136,6 @@ main(int argc, char **argv) } } -#ifdef H5_HAVE_PARALLEL - /* If HDF5 was built with parallel enabled, go ahead and call MPI_Init before - * running these tests. Even though these are meant to be serial tests, they will - * likely be run using mpirun (or similar) and we cannot necessarily expect HDF5 or - * an HDF5 VOL connector to call MPI_Init. - */ - MPI_Init(&argc, &argv); -#endif - H5open(); n_tests_run_g = 0; @@ -304,9 +295,5 @@ main(int argc, char **argv) H5close(); -#ifdef H5_HAVE_PARALLEL - MPI_Finalize(); -#endif - exit(((err_occurred || n_tests_failed_g > 0) ? EXIT_FAILURE : EXIT_SUCCESS)); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 246f1df73e1..fa73a0f7fc2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,6 +27,15 @@ set (TEST_LIB_HEADERS ${HDF5_TEST_SOURCE_DIR}/swmr_common.h ) +################################################################################# +# Set private compile-time definitions added when +# compiling test source files +################################################################################# +set (HDF5_TEST_COMPILE_DEFS_PRIVATE + "$<$:${HDF5_DEVELOPER_DEFS}>" + "$<$:H5_HAVE_TEST_API>" +) + if (BUILD_STATIC_LIBS) add_library (${HDF5_TEST_LIB_TARGET} STATIC ${TEST_LIB_SOURCES} ${TEST_LIB_HEADERS}) target_include_directories (${HDF5_TEST_LIB_TARGET} @@ -37,7 +46,7 @@ if (BUILD_STATIC_LIBS) target_compile_definitions(${HDF5_TEST_LIB_TARGET} PRIVATE "H5_TEST_EXPRESS_LEVEL_DEFAULT=${H5_TEST_EXPRESS_LEVEL_DEFAULT}" - "$<$:${HDF5_DEVELOPER_DEFS}>" + "${HDF5_TEST_COMPILE_DEFS_PRIVATE}" ) TARGET_C_PROPERTIES (${HDF5_TEST_LIB_TARGET} STATIC) target_link_libraries (${HDF5_TEST_LIB_TARGET} @@ -79,7 +88,7 @@ if (BUILD_SHARED_LIBS) "H5_BUILT_AS_DYNAMIC_LIB" PRIVATE "H5_TEST_EXPRESS_LEVEL_DEFAULT=${H5_TEST_EXPRESS_LEVEL_DEFAULT}" - "$<$:${HDF5_DEVELOPER_DEFS}>" + "${HDF5_TEST_COMPILE_DEFS_PRIVATE}" ) TARGET_C_PROPERTIES (${HDF5_TEST_LIBSH_TARGET} SHARED) target_link_libraries (${HDF5_TEST_LIBSH_TARGET} @@ -431,10 +440,7 @@ macro (ADD_H5_EXE file) add_executable (${file} ${HDF5_TEST_SOURCE_DIR}/${file}.c) target_include_directories (${file} PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};${HDF5_TEST_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") target_compile_options(${file} PRIVATE "${HDF5_CMAKE_C_FLAGS}") - target_compile_definitions(${file} - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" - ) + target_compile_definitions(${file} PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (${file} STATIC) target_link_libraries (${file} PRIVATE ${HDF5_TEST_LIB_TARGET}) @@ -475,10 +481,7 @@ endforeach () #-- Adding test for chunk_info add_executable (chunk_info ${HDF5_TEST_SOURCE_DIR}/chunk_info.c) target_compile_options(chunk_info PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(chunk_info - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(chunk_info PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (chunk_info PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};${HDF5_TEST_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (chunk_info STATIC) @@ -499,10 +502,7 @@ endif () #-- Adding test for direct_chunk add_executable (direct_chunk ${HDF5_TEST_SOURCE_DIR}/direct_chunk.c) target_compile_options(direct_chunk PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(direct_chunk - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(direct_chunk PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (direct_chunk PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};${HDF5_TEST_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (direct_chunk STATIC) @@ -524,10 +524,7 @@ endif () #-- Adding test for testhdf5 add_executable (testhdf5 ${testhdf5_SOURCES}) target_compile_options(testhdf5 PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(testhdf5 - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(testhdf5 PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (testhdf5 PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (testhdf5 STATIC) @@ -548,10 +545,7 @@ endif () #-- Adding test for cache_image add_executable (cache_image ${cache_image_SOURCES}) target_compile_options(cache_image PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(cache_image - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(cache_image PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (cache_image PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (cache_image STATIC) @@ -572,10 +566,7 @@ endif () #-- Adding test for ttsafe add_executable (ttsafe ${ttsafe_SOURCES}) target_compile_options(ttsafe PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(ttsafe - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(ttsafe PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (ttsafe PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (ttsafe STATIC) @@ -602,10 +593,7 @@ endif () #-- Adding test for thread_id add_executable (thread_id ${HDF5_TEST_SOURCE_DIR}/thread_id.c) target_compile_options(thread_id PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(thread_id - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(thread_id PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (thread_id PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (thread_id STATIC) @@ -712,10 +700,7 @@ macro (ADD_H5_VDS_EXE file) add_executable (${file} ${HDF5_TEST_SOURCE_DIR}/${file}.c ${HDF5_TEST_SOURCE_DIR}/vds_swmr.h) target_include_directories (${file} PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_BINARY_DIR};${HDF5_TEST_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") target_compile_options(${file} PRIVATE "${HDF5_CMAKE_C_FLAGS}") - target_compile_definitions(${file} - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" - ) + target_compile_definitions(${file} PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (${file} STATIC) target_link_libraries (${file} PRIVATE ${HDF5_TEST_LIB_TARGET}) @@ -742,10 +727,7 @@ endforeach () # and it can't be renamed (i.e., no -shared). add_executable (accum_swmr_reader ${HDF5_TEST_SOURCE_DIR}/accum_swmr_reader.c) target_compile_options(accum_swmr_reader PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(accum_swmr_reader - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(accum_swmr_reader PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (accum_swmr_reader PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (accum_swmr_reader STATIC) @@ -816,10 +798,7 @@ endif () set (use_append_chunk_SOURCES ${HDF5_TEST_SOURCE_DIR}/use_append_chunk.c ${HDF5_TEST_SOURCE_DIR}/use_common.c ${HDF5_TEST_SOURCE_DIR}/use.h) add_executable (use_append_chunk ${use_append_chunk_SOURCES}) target_compile_options(use_append_chunk PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(use_append_chunk - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(use_append_chunk PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (use_append_chunk PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (use_append_chunk STATIC) @@ -841,10 +820,7 @@ if (HDF5_BUILD_UTILS) # requires mirror server set (use_append_chunk_mirror_SOURCES ${HDF5_TEST_SOURCE_DIR}/use_append_chunk_mirror.c ${HDF5_TEST_SOURCE_DIR}/use_common.c ${HDF5_TEST_SOURCE_DIR}/use.h) add_executable (use_append_chunk_mirror ${use_append_chunk_mirror_SOURCES}) target_compile_options(use_append_chunk_mirror PRIVATE "${HDF5_CMAKE_C_FLAGS}") - target_compile_definitions(use_append_chunk_mirror - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" - ) + target_compile_definitions(use_append_chunk_mirror PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (use_append_chunk_mirror PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (use_append_chunk_mirror STATIC) @@ -866,10 +842,7 @@ endif () set (use_append_mchunks_SOURCES ${HDF5_TEST_SOURCE_DIR}/use_append_mchunks.c ${HDF5_TEST_SOURCE_DIR}/use_common.c ${HDF5_TEST_SOURCE_DIR}/use.h) add_executable (use_append_mchunks ${use_append_mchunks_SOURCES}) target_compile_options(use_append_mchunks PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(use_append_mchunks - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(use_append_mchunks PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (use_append_mchunks PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (use_append_mchunks STATIC) @@ -890,10 +863,7 @@ endif () set (use_disable_mdc_flushes_SOURCES ${HDF5_TEST_SOURCE_DIR}/use_disable_mdc_flushes.c) add_executable (use_disable_mdc_flushes ${use_disable_mdc_flushes_SOURCES}) target_compile_options(use_disable_mdc_flushes PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(use_disable_mdc_flushes - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(use_disable_mdc_flushes PRIVATE "${HDF5_TEST_COMPILE_DEFS_PRIVATE}") target_include_directories (use_disable_mdc_flushes PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (use_disable_mdc_flushes STATIC) diff --git a/testpar/API/CMakeLists.txt b/testpar/API/CMakeLists.txt index 869a925d07c..e9c7edd176e 100644 --- a/testpar/API/CMakeLists.txt +++ b/testpar/API/CMakeLists.txt @@ -94,7 +94,7 @@ target_compile_options ( target_compile_definitions ( h5_api_test_parallel PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" + "${HDF5_TESTPAR_COMPILE_DEFS_PRIVATE}" ) if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (h5_api_test_parallel STATIC) diff --git a/testpar/CMakeLists.txt b/testpar/CMakeLists.txt index 7894cffa1da..106f79eba1e 100644 --- a/testpar/CMakeLists.txt +++ b/testpar/CMakeLists.txt @@ -21,13 +21,19 @@ set (testphdf5_SOURCES ${HDF5_TEST_PAR_SOURCE_DIR}/t_oflush.c ) +################################################################################# +# Set private compile-time definitions added when +# compiling test source files +################################################################################# +set (HDF5_TESTPAR_COMPILE_DEFS_PRIVATE + "$<$:${HDF5_DEVELOPER_DEFS}>" + "$<$:H5_HAVE_TEST_API>" +) + #-- Adding test for testhdf5 add_executable (testphdf5 ${testphdf5_SOURCES}) target_compile_options(testphdf5 PRIVATE "${HDF5_CMAKE_C_FLAGS}") -target_compile_definitions(testphdf5 - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" -) +target_compile_definitions(testphdf5 PRIVATE "${HDF5_TESTPAR_COMPILE_DEFS_PRIVATE}") target_include_directories (testphdf5 PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" ) @@ -54,10 +60,7 @@ endif () macro (ADD_H5P_EXE file) add_executable (${file} ${HDF5_TEST_PAR_SOURCE_DIR}/${file}.c) target_compile_options(${file} PRIVATE "${HDF5_CMAKE_C_FLAGS}") - target_compile_definitions(${file} - PRIVATE - "$<$:${HDF5_DEVELOPER_DEFS}>" - ) + target_compile_definitions(${file} PRIVATE "${HDF5_TESTPAR_COMPILE_DEFS_PRIVATE}") target_include_directories (${file} PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" ) diff --git a/testpar/t_bigio.c b/testpar/t_bigio.c index 2726f91b55c..11b47a86a23 100644 --- a/testpar/t_bigio.c +++ b/testpar/t_bigio.c @@ -1854,7 +1854,13 @@ main(int argc, char **argv) { hsize_t newsize = 1048576; /* Set the bigio processing limit to be 'newsize' bytes */ - hsize_t oldsize = H5_mpi_set_bigio_count(newsize); + hsize_t oldsize = H5_mpi_set_bigio_count(newsize); + hid_t acc_plist = H5I_INVALID_HID; +#ifdef H5_HAVE_TEST_API + int required = MPI_THREAD_MULTIPLE; + int provided; +#endif + int mpi_code; /* Having set the bigio handling to a size that is manageable, * we'll set our 'bigcount' variable to be 2X that limit so @@ -1864,9 +1870,37 @@ main(int argc, char **argv) if (newsize != oldsize) bigcount = newsize * 2; - MPI_Init(&argc, &argv); - MPI_Comm_size(MPI_COMM_WORLD, &mpi_size_g); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_g); +#ifdef H5_HAVE_TEST_API + /* Attempt to initialize with MPI_THREAD_MULTIPLE if possible */ + if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(&argc, &argv, required, &provided))) { + printf("MPI_Init_thread failed with error code %d\n", mpi_code); + return -1; + } +#else + if (MPI_SUCCESS != (mpi_code = MPI_Init(&argc, &argv))) { + printf("MPI_Init failed with error code %d\n", mpi_code); + return -1; + } +#endif + + if (MPI_SUCCESS != (mpi_code = MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_g))) { + printf("MPI_Comm_rank failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } + +#ifdef H5_HAVE_TEST_API + /* Warn about missing MPI_THREAD_MULTIPLE support */ + if ((provided < required) && MAIN_PROCESS) + printf("** MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE **\n"); +#endif + + if (MPI_SUCCESS != (mpi_code = MPI_Comm_size(MPI_COMM_WORLD, &mpi_size_g))) { + if (MAIN_PROCESS) + printf("MPI_Comm_size failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } /* Attempt to turn off atexit post processing so that in case errors * happen during the test and the process is aborted, it will not get diff --git a/testpar/t_pshutdown.c b/testpar/t_pshutdown.c index b0b5da71fbf..5293d35ba37 100644 --- a/testpar/t_pshutdown.c +++ b/testpar/t_pshutdown.c @@ -41,10 +41,43 @@ main(int argc, char **argv) hsize_t stride[RANK]; hsize_t block[RANK]; DATATYPE *data_array = NULL; /* data buffer */ + int mpi_code; +#ifdef H5_HAVE_TEST_API + int required = MPI_THREAD_MULTIPLE; + int provided; +#endif + +#ifdef H5_HAVE_TEST_API + /* Attempt to initialize with MPI_THREAD_MULTIPLE if possible */ + if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(&argc, &argv, required, &provided))) { + printf("MPI_Init_thread failed with error code %d\n", mpi_code); + return -1; + } +#else + if (MPI_SUCCESS != (mpi_code = MPI_Init(&argc, &argv))) { + printf("MPI_Init failed with error code %d\n", mpi_code); + return -1; + } +#endif - MPI_Init(&argc, &argv); - MPI_Comm_size(comm, &mpi_size); - MPI_Comm_rank(comm, &mpi_rank); + if (MPI_SUCCESS != (mpi_code = MPI_Comm_rank(comm, &mpi_rank))) { + printf("MPI_Comm_rank failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } + +#ifdef H5_HAVE_TEST_API + /* Warn about missing MPI_THREAD_MULTIPLE support */ + if ((provided < required) && MAINPROCESS) + printf("** MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE **\n"); +#endif + + if (MPI_SUCCESS != (mpi_code = MPI_Comm_size(comm, &mpi_size))) { + if (MAINPROCESS) + printf("MPI_Comm_size failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } if (MAINPROCESS) TESTING("proper shutdown of HDF5 library"); diff --git a/testpar/t_shapesame.c b/testpar/t_shapesame.c index 0a3d3d0a49e..e2112d51798 100644 --- a/testpar/t_shapesame.c +++ b/testpar/t_shapesame.c @@ -4254,6 +4254,11 @@ int main(int argc, char **argv) { int mpi_size, mpi_rank; /* mpi variables */ + int mpi_code; +#ifdef H5_HAVE_TEST_API + int required = MPI_THREAD_MULTIPLE; + int provided; +#endif #ifndef H5_HAVE_WIN32_API /* Un-buffer the stdout and stderr */ @@ -4261,9 +4266,37 @@ main(int argc, char **argv) HDsetbuf(stdout, NULL); #endif - MPI_Init(&argc, &argv); - MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); +#ifdef H5_HAVE_TEST_API + /* Attempt to initialize with MPI_THREAD_MULTIPLE if possible */ + if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(&argc, &argv, required, &provided))) { + printf("MPI_Init_thread failed with error code %d\n", mpi_code); + return -1; + } +#else + if (MPI_SUCCESS != (mpi_code = MPI_Init(&argc, &argv))) { + printf("MPI_Init failed with error code %d\n", mpi_code); + return -1; + } +#endif + + if (MPI_SUCCESS != (mpi_code = MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank))) { + printf("MPI_Comm_rank failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } + +#ifdef H5_HAVE_TEST_API + /* Warn about missing MPI_THREAD_MULTIPLE support */ + if ((provided < required) && MAINPROCESS) + printf("** MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE **\n"); +#endif + + if (MPI_SUCCESS != (mpi_code = MPI_Comm_size(MPI_COMM_WORLD, &mpi_size))) { + if (MAINPROCESS) + printf("MPI_Comm_size failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } mpi_rank_framework_g = mpi_rank; diff --git a/testpar/testphdf5.c b/testpar/testphdf5.c index e094ad6dcd3..831b9def125 100644 --- a/testpar/testphdf5.c +++ b/testpar/testphdf5.c @@ -301,10 +301,15 @@ int main(int argc, char **argv) { int mpi_size, mpi_rank; /* mpi variables */ + int mpi_code; H5Ptest_param_t ndsets_params, ngroups_params; H5Ptest_param_t collngroups_params; H5Ptest_param_t io_mode_confusion_params; H5Ptest_param_t rr_obj_flush_confusion_params; +#ifdef H5_HAVE_TEST_API + int required = MPI_THREAD_MULTIPLE; + int provided; +#endif #ifndef H5_HAVE_WIN32_API /* Un-buffer the stdout and stderr */ @@ -312,9 +317,37 @@ main(int argc, char **argv) HDsetbuf(stdout, NULL); #endif - MPI_Init(&argc, &argv); - MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); +#ifdef H5_HAVE_TEST_API + /* Attempt to initialize with MPI_THREAD_MULTIPLE if possible */ + if (MPI_SUCCESS != (mpi_code = MPI_Init_thread(&argc, &argv, required, &provided))) { + printf("MPI_Init_thread failed with error code %d\n", mpi_code); + return -1; + } +#else + if (MPI_SUCCESS != (mpi_code = MPI_Init(&argc, &argv))) { + printf("MPI_Init failed with error code %d\n", mpi_code); + return -1; + } +#endif + + if (MPI_SUCCESS != (mpi_code = MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank))) { + printf("MPI_Comm_rank failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } + +#ifdef H5_HAVE_TEST_API + /* Warn about missing MPI_THREAD_MULTIPLE support */ + if ((provided < required) && MAINPROCESS) + printf("** MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE **\n"); +#endif + + if (MPI_SUCCESS != (mpi_code = MPI_Comm_size(MPI_COMM_WORLD, &mpi_size))) { + if (MAINPROCESS) + printf("MPI_Comm_size failed with error code %d\n", mpi_code); + MPI_Finalize(); + return -1; + } mpi_rank_framework_g = mpi_rank;