Skip to content

Commit 618c54e

Browse files
committed
allow non-MPI build option -Dhdf5_parallel=off (default on)
1 parent 5fbc829 commit 618c54e

File tree

5 files changed

+64
-55
lines changed

5 files changed

+64
-55
lines changed

CMakeLists.txt

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,33 @@ endif()
3131
include(cmake/options.cmake)
3232
include(cmake/compilers.cmake)
3333

34-
if(ourFindMPI)
35-
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules/MPI)
34+
if(hdf5_parallel)
35+
find_package(MPI COMPONENTS C Fortran REQUIRED)
36+
37+
include(cmake/check_mpi.cmake)
38+
check_mpi_version()
39+
40+
find_package(HDF5 COMPONENTS Fortran parallel REQUIRED)
41+
if(HDF5_VERSION VERSION_LESS 1.10.2)
42+
message(WARNING "HDF5 >= 1.10.2 is needed for HDF5-MPI")
43+
endif()
44+
else()
45+
find_package(HDF5 COMPONENTS Fortran REQUIRED)
3646
endif()
3747

38-
find_package(MPI COMPONENTS C Fortran REQUIRED)
39-
40-
41-
# --- external libraries: HDF5
42-
43-
include(cmake/check_mpi.cmake)
44-
check_mpi_version()
45-
46-
find_package(HDF5 COMPONENTS Fortran HL parallel REQUIRED)
47-
if(HDF5_VERSION VERSION_LESS 1.10.2)
48-
message(WARNING "HDF5 >= 1.10.2 is needed for HDF5-MPI")
49-
endif()
50-
51-
# --- HDF5-MPI object oriented API
48+
# --- h5fortran object oriented API
5249

5350
add_library(h5fortran)
54-
target_compile_definitions(h5fortran PRIVATE -Dh5fortran_HAVE_PARALLEL)
51+
target_compile_definitions(h5fortran PRIVATE
52+
$<$<BOOL:${hdf5_parallel}>:h5fortran_HAVE_PARALLEL>
53+
)
5554
target_include_directories(h5fortran PUBLIC
5655
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
5756
$<INSTALL_INTERFACE:include>
5857
)
59-
target_link_libraries(h5fortran PUBLIC HDF5::HDF5 MPI::MPI_Fortran)
58+
target_link_libraries(h5fortran PUBLIC HDF5::HDF5
59+
$<$<BOOL:${hdf5_parallel}>:MPI::MPI_Fortran>
60+
)
6061
set_target_properties(h5fortran PROPERTIES
6162
Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
6263
LABELS core

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
[![intel-oneapi](https://github.com/geospace-code/h5fortran-mpi/actions/workflows/intel-oneapi.yml/badge.svg)](https://github.com/geospace-code/h5fortran-mpi/actions/workflows/intel-oneapi.yml)
88

99
Easy to use object-oriented Fortran [parallel HDF5-MPI](https://portal.hdfgroup.org/display/HDF5/Parallel+HDF5) interface.
10-
This interface requires MPI, although it is capable of non-MPI file I/O.
11-
The original object-oriented Fortran HDF5 interface **without MPI** is [h5fortran](https://github.com/geospace-code/h5fortran).
12-
The [h5fortran-mpi API](./API.md)
13-
is by design nearly identical to the non-MPI serial h5fortran API.
14-
A very similar NetCDF4 interface is [nc4fortran](https://github.com/geospace-code/nc4fortran).
10+
The [h5fortran-mpi API](./API.md) can be used with or with MPI.
11+
A very similar NetCDF4 interface is
12+
[nc4fortran](https://github.com/geospace-code/nc4fortran).
1513

1614
Many computer systems default to the serial HDF5 API, which lacks the HDF5 parallel MPI layer.
1715
The scripts/CMakeLists.txt can build the HDF5-MPI stack if needed.
@@ -24,7 +22,7 @@ Some OS have an installable parallel HDF5 package:
2422
* MacOS Homebrew: `brew install hdf5-mpi`
2523
* MacOS MacPorts: `port install hdf5 +fortran +mpich`
2624

27-
While HDF5 1.10.2 is the oldest working HDF5 version, and the CI includes HDF5 1.10.4, in general for bugfixes and performance HDF5 &ge; 1.10.5 is [recommended](https://portal.hdfgroup.org/display/knowledge/OpenMPI+Build+Issues).
25+
While HDF5 1.10.2 is the oldest working HDF5 version, in general for bugfixes and performance HDF5 &ge; 1.10.5 is [recommended](https://portal.hdfgroup.org/display/knowledge/OpenMPI+Build+Issues).
2826
For highest performance with parallel compressed writes consider HDF5 &ge; 1.12.2.
2927

3028
## Compressed parallel HDF5
@@ -62,12 +60,19 @@ cmake -B build -DHDF5_ROOT=~/lib_par
6260
cmake --build build
6361
```
6462

63+
To build without MPI (serial HDF5 file operations only):
64+
65+
```sh
66+
cmake -B build -Dhdf5_parallel=off
67+
```
68+
6569
---
6670

6771
Fortran Package Manager (FPM) users build like:
6872

6973
```sh
7074
fpm build --flag -Dh5fortran_HAVE_PARALLEL
75+
# omitting this flag builds the serial API only
7176

7277
fpm test
7378
```

cmake/hdf5.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if(hdf5_parallel)
88
find_package(MPI REQUIRED COMPONENTS C)
99
endif()
1010

11-
# pass MPI hints to HDF5
11+
# pass MPI hints to HDF5, which needs it as a CMake variable--HDF5 project doesn't detect ENV{MPI_ROOT}
1212
if(NOT MPI_ROOT AND DEFINED ENV{MPI_ROOT})
1313
set(MPI_ROOT $ENV{MPI_ROOT})
1414
endif()

cmake/options.cmake

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
option(ENABLE_BENCHMARKS "write / read benchmarks")
1+
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION}")
22

3+
option(ENABLE_BENCHMARKS "write / read benchmarks")
34
option(ENABLE_COVERAGE "Code coverage tests")
4-
5-
option(ourFindMPI "Use our FindMPI")
6-
7-
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION}")
5+
option(hdf5_parallel "use HDF5-MPI layer" true)
86

97
set(CMAKE_TLS_VERIFY true)
108

119

12-
if(BUILD_SHARED_LIBS)
13-
if(WIN32 AND CMAKE_VERSION VERSION_LESS 3.21 AND ${PROJECT_NAME}_BUILD_TESTING)
14-
message(STATUS "Windows with shared libs needs CMake >= 3.21 to run tests")
15-
endif()
16-
if(MSVC)
17-
message(WARNING "Intel oneAPI has trouble with shared libs in general on Windows, try
18-
cmake -DBUILD_SHARED_LIBS=off")
19-
endif()
10+
if(BUILD_SHARED_LIBS AND MSVC)
11+
message(WARNING "Intel oneAPI has trouble with shared libs in general on Windows, try
12+
cmake -DBUILD_SHARED_LIBS=off")
2013
endif()
2114

2215
cmake_path(SET CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules)

test/CMakeLists.txt

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
set_directory_properties(PROPERTIES LABELS unit)
22

3-
# --- unit tests
4-
5-
add_executable(test_runner runner.f90
6-
${PROJECT_SOURCE_DIR}/benchmark/cpu.cpp
7-
${PROJECT_SOURCE_DIR}/benchmark/partition.f90
8-
${PROJECT_SOURCE_DIR}/benchmark/cli.f90
9-
)
10-
# not linked as libraries in case benchmarks aren't built
11-
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
12-
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE Fortran)
13-
else()
14-
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE CXX)
15-
endif()
16-
17-
# --- h5fortran unit tests
3+
# --- helper functions
184

195
function(nompi_test names)
206

@@ -58,20 +44,42 @@ add_test(NAME ${name} COMMAND ${cmd})
5844
endforeach()
5945

6046
set_tests_properties(${names} PROPERTIES
61-
RESOUCE_LOCK cpu_mpi
47+
RESOURCE_LOCK cpu_mpi
6248
LABELS mpi
6349
)
6450

6551
endfunction(mpi_test)
6652

53+
# --- test files
54+
6755
cmake_path(SET string_file ${CMAKE_CURRENT_BINARY_DIR}/test_string_py.h5)
6856

69-
# --- write test data
57+
# --- non-MPI tests
7058

7159
set(nompi_tests array)
7260

7361
nompi_test(${nompi_tests})
7462

63+
64+
# --- runner
65+
66+
if(hdf5_parallel)
67+
68+
add_executable(test_runner runner.f90
69+
${PROJECT_SOURCE_DIR}/benchmark/cpu.cpp
70+
${PROJECT_SOURCE_DIR}/benchmark/partition.f90
71+
${PROJECT_SOURCE_DIR}/benchmark/cli.f90
72+
)
73+
# not linked as libraries in case benchmarks aren't built
74+
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
75+
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE Fortran)
76+
else()
77+
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE CXX)
78+
endif()
79+
80+
81+
# --- MPI tests
82+
7583
set(mpi_tests array_mpi attributes cast destructor exist fill groups layout shape
7684
string string_read write
7785
)
@@ -136,6 +144,8 @@ FIXTURES_SETUP h5str
136144
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
137145
)
138146

147+
endif(hdf5_parallel)
148+
139149
# --- test properties
140150

141151
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)

0 commit comments

Comments
 (0)