Skip to content

Commit 7c4587b

Browse files
committed
example
1 parent d414efb commit 7c4587b

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Examples/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.20...3.22)
2+
3+
project(h5mpiExample
4+
LANGUAGES Fortran
5+
)
6+
7+
enable_testing()
8+
9+
find_package(h5mpi CONFIG REQUIRED)
10+
11+
# --- example 1
12+
add_executable(example1 example1.f90)
13+
target_link_libraries(example1 h5mpi::h5mpi)
14+
15+
add_test(NAME Example1
16+
COMMAND $<TARGET_FILE:example1>
17+
)
18+
set_tests_properties(Example1 PROPERTIES
19+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
20+
TIMEOUT 10
21+
)

Examples/example1.f90

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
program example2
2+
3+
use, intrinsic :: iso_fortran_env, only : real32
4+
5+
use mpi, only : mpi_init, mpi_finalize
6+
7+
use h5mpi, only : hdf5_file, HSIZE_T
8+
9+
implicit none (type, external)
10+
11+
character(*), parameter :: filename = 'example1.h5'
12+
integer :: ierr, mpi_id, Nmpi
13+
14+
type(hdf5_file) :: h5f
15+
16+
call mpi_init(ierr)
17+
if (ierr /= 0) error stop "mpi_init failed"
18+
19+
call mpi_comm_size(MPI_COMM_WORLD, Nmpi, ierr)
20+
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
21+
if (ierr /= 0) error stop "mpi_comm_rank failed"
22+
23+
if(mpi_id == 0) then
24+
25+
call h5f%open(filename, action='w', mpi=.false.)
26+
call h5f%write('/x', 123)
27+
call h5f%close()
28+
29+
call h5f%open(filename, action='r', mpi=.false.)
30+
call h5f%read('/x', i32)
31+
if (i32 /= 123) error stop 'incorrect value read'
32+
33+
print *, 'OK: non-MPI write / read'
34+
35+
endif
36+
37+
call mpi_finalize(ierr)
38+
39+
end program

0 commit comments

Comments
 (0)