Skip to content

Commit 60247db

Browse files
committed
add nompi deflate tests
add nompi destructor tests
1 parent 1ef48ba commit 60247db

11 files changed

+708
-283
lines changed

test/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@ cmake_path(SET string_file ${CMAKE_CURRENT_BINARY_DIR}/test_string_py.h5)
5656

5757
# --- non-MPI tests
5858

59-
set(nompi_tests array attributes cast)
59+
set(nompi_tests array attributes cast deflate_props deflate_read deflate_write destructor
60+
exist
61+
)
6062

6163
nompi_test("${nompi_tests}")
6264

65+
set_tests_properties(deflate_write PROPERTIES
66+
FIXTURES_SETUP deflate_files
67+
)
68+
69+
set_tests_properties(deflate_props deflate_read PROPERTIES
70+
FIXTURES_REQUIRED deflate_files
71+
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
72+
)
73+
6374

6475
# --- runner
6576

@@ -80,13 +91,14 @@ endif()
8091

8192
# --- MPI tests
8293

83-
set(mpi_tests array_mpi attributes_mpi cast_mpi destructor exist fill groups layout shape
94+
set(mpi_tests array_mpi attributes_mpi cast_mpi destructor_mpi exist_mpi
95+
fill groups layout shape
8496
string string_read write
8597
)
8698

8799
mpi_test("${mpi_tests}" false)
88100

89-
set(runner_tests deflate_write deflate_props deflate_read)
101+
set(runner_tests deflate_write_mpi deflate_props_mpi deflate_read_mpi)
90102

91103
mpi_test("${runner_tests}" true)
92104

@@ -101,12 +113,12 @@ FIXTURES_REQUIRED test_files
101113
REQUIRED_FILES "${CMAKE_CURRENT_BINARY_DIR}/test_write.h5;${CMAKE_CURRENT_BINARY_DIR}/test_layout.h5"
102114
)
103115

104-
set_tests_properties(deflate_write PROPERTIES
105-
FIXTURES_SETUP deflate_files
116+
set_tests_properties(deflate_write_mpi PROPERTIES
117+
FIXTURES_SETUP deflate_files_mpi
106118
)
107119

108-
set_tests_properties(deflate_props deflate_read PROPERTIES
109-
FIXTURES_REQUIRED deflate_files
120+
set_tests_properties(deflate_props_mpi deflate_read_mpi PROPERTIES
121+
FIXTURES_REQUIRED deflate_files_mpi
110122
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
111123
)
112124

test/test_deflate_props.f90

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,42 @@ program test_deflate_props
33
use, intrinsic :: iso_fortran_env, only : int64, stderr=>output_unit
44

55
use hdf5, only : H5D_CHUNKED_F, H5D_CONTIGUOUS_F
6-
use mpi, only : mpi_init, mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD
76

8-
use h5fortran, only: hdf5_file, HSIZE_T, has_parallel_compression
7+
use h5fortran, only: hdf5_file, HSIZE_T
98

109
implicit none (type, external)
1110

12-
external :: mpi_finalize
13-
1411
character(*), parameter :: fn1='deflate1.h5'
1512
integer, parameter :: N(2) = [50, 1000], &
1613
MIN_COMP = 2 !< lots of CPUs, smaller arrays => poorer compression
1714

18-
integer :: ierr, mpi_id
19-
20-
21-
call mpi_init(ierr)
22-
if (ierr /= 0) error stop "mpi_init"
23-
24-
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
25-
if(ierr/=0) error stop "mpi_comm_rank"
26-
27-
call test_read_deflate_props(fn1, N, mpi_id)
28-
if(mpi_id == 0) print *,'OK: HDF5 read deflate properties'
15+
call test_read_deflate_props(fn1, N)
16+
print *,'OK: HDF5 read deflate properties'
2917

3018
call test_get_deflate(fn1)
31-
if(mpi_id == 0) print *, 'OK: HDF5 get deflate'
32-
33-
call mpi_finalize(ierr)
34-
if (ierr /= 0) error stop "mpi_finalize"
19+
print *, 'OK: HDF5 get deflate'
3520

3621
contains
3722

3823

39-
subroutine test_read_deflate_props(fn, N, mpi_id)
24+
subroutine test_read_deflate_props(fn, N)
4025

4126
character(*), intent(in) :: fn
42-
integer, intent(in) :: N(2), mpi_id
27+
integer, intent(in) :: N(2)
4328

4429
type(hdf5_file) :: h5f
4530

46-
integer :: fsize, layout
47-
integer(int64) :: crat
31+
integer :: layout
32+
real :: fsize, crat
4833
integer(HSIZE_T) :: chunks(2)
4934

50-
if(mpi_id == 0) then
51-
inquire(file=fn, size=fsize)
52-
crat = (N(1) * N(2) * 32 / 8) / fsize
53-
print '(A,F6.2,A,I6)','#1 filesize (Mbytes): ',fsize/1e6, ' compression ratio:',crat
54-
if (has_parallel_compression()) then
55-
if(crat < MIN_COMP) error stop '2D low compression'
56-
else
57-
print *, "test_read_deflate_props: MPI commpression was disabled, so " // fn // " was not compressed."
58-
endif
59-
endif
35+
call h5f%open(fn, action='r')
36+
37+
fsize = real(h5f%filesize())
6038

61-
call h5f%open(fn, action='r', mpi=.true.)
39+
crat = (N(1) * N(2) * 32 / 8) / fsize
40+
print '(A,F6.2,A,f7.1)','#1 filesize (Mbytes): ',fsize/1e6, ' compression ratio:',crat
41+
if(crat < MIN_COMP) error stop '2D low compression'
6242

6343
layout = h5f%layout('/A')
6444
if(layout /= H5D_CHUNKED_F) error stop '#1 not chunked layout: ' // fn
@@ -85,15 +65,9 @@ subroutine test_get_deflate(fn)
8565

8666
type(hdf5_file) :: h5f
8767

88-
call h5f%open(fn, action='r', mpi=.true.)
89-
90-
if (h5f%parallel_compression) then
91-
if (.not. h5f%deflate("/A")) error stop "test_get_deflate: expected deflate MPI"
92-
else
93-
if (h5f%deflate("/A")) error stop "test_get_deflate: expected no deflate MPI"
94-
endif
68+
call h5f%open(fn, action='r')
9569

96-
if (.not. h5f%deflate("/noMPI")) error stop "expected deflate as dataset was written without MPI"
70+
if (.not. h5f%deflate("/A")) error stop "test_get_deflate: expected deflate"
9771

9872
call h5f%close()
9973

test/test_deflate_props_mpi.f90

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
program test_deflate_props
2+
3+
use, intrinsic :: iso_fortran_env, only : int64, stderr=>output_unit
4+
5+
use hdf5, only : H5D_CHUNKED_F, H5D_CONTIGUOUS_F
6+
use mpi, only : mpi_init, mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD
7+
8+
use h5fortran, only: hdf5_file, HSIZE_T, has_parallel_compression
9+
10+
implicit none (type, external)
11+
12+
external :: mpi_finalize
13+
14+
character(*), parameter :: fn1='deflate1.h5'
15+
integer, parameter :: N(2) = [50, 1000], &
16+
MIN_COMP = 2 !< lots of CPUs, smaller arrays => poorer compression
17+
18+
integer :: ierr, mpi_id
19+
20+
21+
call mpi_init(ierr)
22+
if (ierr /= 0) error stop "mpi_init"
23+
24+
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
25+
if(ierr/=0) error stop "mpi_comm_rank"
26+
27+
call test_read_deflate_props(fn1, N, mpi_id)
28+
if(mpi_id == 0) print *,'OK: HDF5 read deflate properties'
29+
30+
call test_get_deflate(fn1)
31+
if(mpi_id == 0) print *, 'OK: HDF5 get deflate'
32+
33+
call mpi_finalize(ierr)
34+
if (ierr /= 0) error stop "mpi_finalize"
35+
36+
contains
37+
38+
39+
subroutine test_read_deflate_props(fn, N, mpi_id)
40+
41+
character(*), intent(in) :: fn
42+
integer, intent(in) :: N(2), mpi_id
43+
44+
type(hdf5_file) :: h5f
45+
46+
integer :: fsize, layout
47+
integer(int64) :: crat
48+
integer(HSIZE_T) :: chunks(2)
49+
50+
if(mpi_id == 0) then
51+
inquire(file=fn, size=fsize)
52+
crat = (N(1) * N(2) * 32 / 8) / fsize
53+
print '(A,F6.2,A,I6)','#1 filesize (Mbytes): ',fsize/1e6, ' compression ratio:',crat
54+
if (has_parallel_compression()) then
55+
if(crat < MIN_COMP) error stop '2D low compression'
56+
else
57+
print *, "test_read_deflate_props: MPI commpression was disabled, so " // fn // " was not compressed."
58+
endif
59+
endif
60+
61+
call h5f%open(fn, action='r', mpi=.true.)
62+
63+
layout = h5f%layout('/A')
64+
if(layout /= H5D_CHUNKED_F) error stop '#1 not chunked layout: ' // fn
65+
if(.not.h5f%is_chunked('/A')) error stop '#1 not chunked layout: ' // fn
66+
call h5f%chunks('/A', chunks)
67+
if(chunks(1) /= 5) then
68+
write(stderr, '(a,2I5)') "expected chunks(1) = 5 but got chunks ", chunks
69+
error stop '#1 get_chunk mismatch'
70+
endif
71+
layout = h5f%layout('/small_contig')
72+
if(layout /= H5D_CONTIGUOUS_F) error stop '#1 not contiguous layout'
73+
if(.not.h5f%is_contig('/small_contig')) error stop '#1 not contig layout'
74+
call h5f%chunks('/small_contig', chunks)
75+
if(any(chunks(:2) /= -1)) error stop '#1 get_chunk mismatch'
76+
77+
call h5f%close()
78+
79+
end subroutine test_read_deflate_props
80+
81+
82+
subroutine test_get_deflate(fn)
83+
84+
character(*), intent(in) :: fn
85+
86+
type(hdf5_file) :: h5f
87+
88+
call h5f%open(fn, action='r', mpi=.true.)
89+
90+
if (h5f%parallel_compression) then
91+
if (.not. h5f%deflate("/A")) error stop "test_get_deflate: expected deflate MPI"
92+
else
93+
if (h5f%deflate("/A")) error stop "test_get_deflate: expected no deflate MPI"
94+
endif
95+
96+
if (.not. h5f%deflate("/noMPI")) error stop "expected deflate as dataset was written without MPI"
97+
98+
call h5f%close()
99+
100+
end subroutine test_get_deflate
101+
102+
end program

test/test_deflate_read.f90

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,33 @@
11
program test_deflate_read
22

33
use, intrinsic:: iso_fortran_env, only: int32, int64, real32, real64, stderr=>error_unit
4-
use mpi, only : mpi_init, mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD
54

65
use h5fortran, only: hdf5_file
76

87
implicit none (type, external)
98

10-
external :: mpi_finalize
11-
12-
integer :: ierr, mpi_id, Nmpi
139
character(*), parameter :: fn1='deflate1.h5'
14-
integer, parameter :: N(2) = [50, 1000], &
15-
MIN_COMP = 2 !< lots of CPUs, smaller arrays => poorer compression
16-
17-
18-
call mpi_init(ierr)
19-
if (ierr /= 0) error stop "mpi_init"
20-
21-
call mpi_comm_size(MPI_COMM_WORLD, Nmpi, ierr)
22-
if(ierr/=0) error stop "mpi_comm_size"
23-
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
24-
if(ierr/=0) error stop "mpi_comm_rank"
10+
integer, parameter :: N(2) = [50, 1000]
2511

26-
call test_read_deflate(fn1, N, mpi_id, Nmpi)
27-
if(mpi_id==0) print *,'OK: HDF5 read deflate'
2812

29-
call mpi_finalize(ierr)
30-
if (ierr /= 0) error stop "mpi_finalize"
13+
call test_read_deflate(fn1, N)
14+
print *,'OK: HDF5 read deflate'
3115

3216
contains
3317

34-
subroutine test_read_deflate(fn, N, mpi_id, Nmpi)
18+
subroutine test_read_deflate(fn, N)
3519

3620
character(*), intent(in) :: fn
37-
integer, intent(in) :: N(2), Nmpi, mpi_id
21+
integer, intent(in) :: N(2)
3822

3923
type(hdf5_file) :: h5f
40-
integer :: i0(2), i1(2), dx2
4124
real(real32), allocatable :: A(:,:)
42-
logical :: debug = .false.
43-
44-
!> MPI partition
45-
if(mpi_id == 0) then
46-
if (Nmpi > 1 .and. (modulo(N(2), Nmpi) /= 0 .or. Nmpi > N(2))) then
47-
write(stderr, '(a,1x,i0,1x,i0)') "test_deflate_props: MPI worker count must be multiple of N", N(2), Nmpi
48-
error stop fn
49-
endif
50-
end if
51-
52-
dx2 = N(2) / Nmpi
53-
54-
allocate(A(N(1), dx2))
55-
56-
i0(1) = 1
57-
i0(2) = mpi_id * dx2 + 1
58-
i1(1) = size(A, 1)
59-
i1(2) = i0(2) + dx2 - 1
6025

61-
!> read with MPI
62-
if(debug) print '(a,i0,1x,2i5,2x,2i5)', "#1 partition: mpi_id, i0, i1 ", mpi_id, i0, i1
26+
allocate(A(N(1), N(2)))
6327

64-
call h5f%open(fn, action='r', mpi=.true.)
65-
call h5f%read('/A', A, istart=i0, iend=i1)
66-
call h5f%read('/noMPI', A, istart=i0, iend=i1) !< compressed with MPI
28+
call h5f%open(fn, action='r')
29+
call h5f%read('/A', A)
30+
call h5f%read('/noMPI', A)
6731
call h5f%close()
6832

6933
end subroutine test_read_deflate

0 commit comments

Comments
 (0)