Skip to content

Commit acf1e3b

Browse files
committed
put deflate props tests in own file
add deflate read tests
1 parent c8fcacb commit acf1e3b

File tree

4 files changed

+217
-100
lines changed

4 files changed

+217
-100
lines changed

src/tests/unit/CMakeLists.txt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
set_directory_properties(PROPERTIES LABELS unit)
22

3-
add_executable(test_deflate test_deflate.f90)
4-
target_link_libraries(test_deflate PRIVATE h5mpi HDF5::HDF5 MPI::MPI_Fortran)
5-
63
set(MPI_MAX 1000) # tests a priori have maximum dimension length 1000, which is more than most contemporary computers
74
max_gcd(${MPI_MAX} ${MPIEXEC_MAX_NUMPROCS} Nmpi)
85

96
message(STATUS "Unit tests using ${Nmpi} processes")
107

11-
add_test(NAME deflate
12-
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${Nmpi} $<TARGET_FILE:test_deflate>
13-
)
8+
set(test_names deflate deflate_props deflate_read)
149

15-
set_tests_properties(deflate PROPERTIES
10+
foreach(t IN LISTS test_names)
11+
12+
add_executable(test_${t} test_${t}.f90)
13+
target_link_libraries(test_${t} PRIVATE h5mpi HDF5::HDF5 MPI::MPI_Fortran)
14+
15+
add_test(NAME ${t}
16+
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${Nmpi} $<TARGET_FILE:test_${t}>
17+
)
18+
19+
endforeach()
20+
21+
set_tests_properties(${test_names} PROPERTIES
1622
TIMEOUT 10
1723
PROCESSORS ${Nmpi}
1824
)
25+
26+
set_tests_properties(deflate PROPERTIES
27+
FIXTURES_SETUP deflate_files
28+
)
29+
30+
set_tests_properties(deflate_props deflate_read PROPERTIES
31+
FIXTURES_REQUIRED deflate_files
32+
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
33+
)

src/tests/unit/test_deflate.f90

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ program test_deflate
66

77
use, intrinsic:: iso_fortran_env, only: int32, int64, real32, real64, stderr=>error_unit
88

9-
use hdf5, only : H5D_CHUNKED_F, H5D_CONTIGUOUS_F, hsize_t
109
use mpi, only : mpi_init, mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD
1110

12-
use h5mpi, only: hdf5_file, HSIZE_T, has_parallel_compression
11+
use h5mpi, only: hdf5_file, HSIZE_T
1312

1413
implicit none (type, external)
1514

@@ -18,58 +17,42 @@ program test_deflate
1817
character(*), parameter :: fn1='deflate1.h5', fn2='deflate2.h5', fn3='deflate3.h5'
1918
integer, parameter :: N(2) = [50, 1000], &
2019
MIN_COMP = 2 !< lots of CPUs, smaller arrays => poorer compression
21-
integer :: ierr, mpi_id
20+
integer :: ierr, mpi_id, Nmpi
2221

2322

2423
call mpi_init(ierr)
2524
if (ierr /= 0) error stop "mpi_init"
2625

26+
call mpi_comm_size(MPI_COMM_WORLD, Nmpi, ierr)
27+
if(ierr/=0) error stop "mpi_comm_size"
2728
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
2829
if(ierr/=0) error stop "mpi_comm_rank"
2930

30-
call test_write_deflate(fn1, N)
31+
call test_write_deflate(fn1, N, mpi_id, Nmpi)
3132
if(mpi_id==0) print *,'OK: HDF5 write deflate'
3233

33-
call test_read_deflate_props(fn1, N)
34-
if(mpi_id==0) print *,'OK: HDF5 read deflate properties'
35-
3634
call test_deflate_whole(fn2, N)
3735
if(mpi_id==0) print *,'OK: HDF5 compress whole'
3836

3937
call test_deflate_slice(fn3, N)
4038
if(mpi_id==0) print *,'OK: HDF5 compress slice'
4139

42-
if(mpi_id==0) then
43-
call test_get_deflate(fn1)
44-
!! only works with mpi=.false. else get file close error
45-
print *, 'OK: HDF5 get deflate'
46-
endif
47-
4840
call mpi_finalize(ierr)
4941
if (ierr /= 0) error stop "mpi_finalize"
5042

5143
contains
5244

53-
subroutine test_write_deflate(fn, N)
45+
subroutine test_write_deflate(fn, N, mpi_id, Nmpi)
5446

5547
character(*), intent(in) :: fn
56-
integer, intent(in) :: N(2)
48+
integer, intent(in) :: N(2), mpi_id, Nmpi
5749

5850
type(hdf5_file) :: h5f
59-
6051
integer(HSIZE_T) :: i0(2), i1(2), dx2
61-
integer :: Nmpi, mpi_id
62-
6352
real(real32), allocatable :: A(:,:)
64-
6553
logical :: debug = .false.
6654

6755
!> MPI partition
68-
call mpi_comm_size(MPI_COMM_WORLD, Nmpi, ierr)
69-
if(ierr/=0) error stop "mpi_comm_size"
70-
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
71-
if(ierr/=0) error stop "mpi_comm_rank"
72-
7356
if(mpi_id == 0) then
7457
if (Nmpi > 1 .and. (modulo(N(2), Nmpi) /= 0 .or. Nmpi > N(2))) then
7558
write(stderr, '(a,1x,i0,1x,i0)') "test_deflate_props: MPI worker count must be multiple of N", N(2), Nmpi
@@ -95,14 +78,18 @@ subroutine test_write_deflate(fn, N)
9578
call h5f%write('/A', A, N, istart=i0, iend=i1, chunk_size=[5, 50])
9679
call h5f%close()
9780

81+
deallocate(A)
82+
9883
if(mpi_id == 0) then
99-
!! write small dataset without MPI, with compression of noMPI dataset
84+
allocate(A(N(1), N(2)))
85+
A = 1 !< simplest data
86+
!! write without MPI, with compression of noMPI dataset
10087
call h5f%open(fn, action='a', comp_lvl=1, mpi=.false.)
10188

10289
call h5f%write('/small_contig', A(:4,:4))
10390
!! not compressed because too small
10491

105-
call h5f%write('/noMPI', A(:,:))
92+
call h5f%write('/noMPI', A)
10693
!! write without MPI, with compression
10794

10895
call h5f%close()
@@ -111,51 +98,6 @@ subroutine test_write_deflate(fn, N)
11198
end subroutine test_write_deflate
11299

113100

114-
subroutine test_read_deflate_props(fn, N)
115-
116-
character(*), intent(in) :: fn
117-
integer, dimension(2), intent(in) :: N
118-
119-
type(hdf5_file) :: h5f
120-
121-
integer :: fsize, layout, mpi_id
122-
integer(int64) :: crat
123-
integer(HSIZE_T) :: chunks(2)
124-
125-
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
126-
127-
if(mpi_id == 0) then
128-
inquire(file=fn, size=fsize)
129-
crat = (N(1) * N(2) * 32 / 8) / fsize
130-
print '(A,F6.2,A,I6)','#1 filesize (Mbytes): ',fsize/1e6, ' compression ratio:',crat
131-
if (has_parallel_compression()) then
132-
if(crat < MIN_COMP) error stop '2D low compression'
133-
else
134-
print *, "test_read_deflate_props: MPI commpression was disabled, so " // fn // " was not compressed."
135-
endif
136-
endif
137-
138-
call h5f%open(fn, action='r', mpi=.true.)
139-
140-
layout = h5f%layout('/A')
141-
if(layout /= H5D_CHUNKED_F) error stop '#1 not chunked layout: ' // fn
142-
if(.not.h5f%is_chunked('/A')) error stop '#1 not chunked layout: ' // fn
143-
call h5f%chunks('/A', chunks)
144-
if(chunks(1) /= 5) then
145-
write(stderr, '(a,2I5)') "expected chunks(1) = 5 but got chunks ", chunks
146-
error stop '#1 get_chunk mismatch'
147-
endif
148-
layout = h5f%layout('/small_contig')
149-
if(layout /= H5D_CONTIGUOUS_F) error stop '#1 not contiguous layout'
150-
if(.not.h5f%is_contig('/small_contig')) error stop '#1 not contig layout'
151-
call h5f%chunks('/small_contig', chunks)
152-
if(any(chunks(:2) /= -1)) error stop '#1 get_chunk mismatch'
153-
154-
call h5f%close()
155-
156-
end subroutine test_read_deflate_props
157-
158-
159101
subroutine test_deflate_whole(fn, N)
160102

161103
character(*), intent(in) :: fn
@@ -271,26 +213,4 @@ subroutine test_deflate_slice(fn, N)
271213
end subroutine test_deflate_slice
272214

273215

274-
subroutine test_get_deflate(fn)
275-
276-
character(*), intent(in) :: fn
277-
278-
type(hdf5_file) :: h5f
279-
280-
call h5f%open(fn, action='r', mpi=.false.)
281-
!! bug in HDF5? only works with MPI=.false.
282-
283-
if (h5f%parallel_compression) then
284-
if (.not. h5f%deflate("/A")) error stop "test_get_deflate: expected deflate MPI"
285-
else
286-
if (h5f%deflate("/A")) error stop "test_get_deflate: expected no deflate MPI"
287-
endif
288-
289-
if (.not. h5f%deflate("/noMPI")) error stop "expected deflate as dataset was written without MPI"
290-
291-
call h5f%close()
292-
293-
end subroutine test_get_deflate
294-
295-
296216
end program

src/tests/unit/test_deflate_props.f90

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 h5mpi, 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+
if(mpi_id==0) then
31+
call test_get_deflate(fn1)
32+
!! only works with mpi=.false. else get file close error
33+
print *, 'OK: HDF5 get deflate'
34+
endif
35+
36+
call mpi_finalize(ierr)
37+
if (ierr /= 0) error stop "mpi_finalize"
38+
39+
contains
40+
41+
42+
subroutine test_read_deflate_props(fn, N, mpi_id)
43+
44+
character(*), intent(in) :: fn
45+
integer, intent(in) :: N(2), mpi_id
46+
47+
type(hdf5_file) :: h5f
48+
49+
integer :: fsize, layout
50+
integer(int64) :: crat
51+
integer(HSIZE_T) :: chunks(2)
52+
53+
if(mpi_id == 0) then
54+
inquire(file=fn, size=fsize)
55+
crat = (N(1) * N(2) * 32 / 8) / fsize
56+
print '(A,F6.2,A,I6)','#1 filesize (Mbytes): ',fsize/1e6, ' compression ratio:',crat
57+
if (has_parallel_compression()) then
58+
if(crat < MIN_COMP) error stop '2D low compression'
59+
else
60+
print *, "test_read_deflate_props: MPI commpression was disabled, so " // fn // " was not compressed."
61+
endif
62+
endif
63+
64+
call h5f%open(fn, action='r', mpi=.true.)
65+
66+
layout = h5f%layout('/A')
67+
if(layout /= H5D_CHUNKED_F) error stop '#1 not chunked layout: ' // fn
68+
if(.not.h5f%is_chunked('/A')) error stop '#1 not chunked layout: ' // fn
69+
call h5f%chunks('/A', chunks)
70+
if(chunks(1) /= 5) then
71+
write(stderr, '(a,2I5)') "expected chunks(1) = 5 but got chunks ", chunks
72+
error stop '#1 get_chunk mismatch'
73+
endif
74+
layout = h5f%layout('/small_contig')
75+
if(layout /= H5D_CONTIGUOUS_F) error stop '#1 not contiguous layout'
76+
if(.not.h5f%is_contig('/small_contig')) error stop '#1 not contig layout'
77+
call h5f%chunks('/small_contig', chunks)
78+
if(any(chunks(:2) /= -1)) error stop '#1 get_chunk mismatch'
79+
80+
call h5f%close()
81+
82+
end subroutine test_read_deflate_props
83+
84+
85+
subroutine test_get_deflate(fn)
86+
87+
character(*), intent(in) :: fn
88+
89+
type(hdf5_file) :: h5f
90+
91+
call h5f%open(fn, action='r', mpi=.false.)
92+
!! bug in HDF5? only works with MPI=.false.
93+
94+
if (h5f%parallel_compression) then
95+
if (.not. h5f%deflate("/A")) error stop "test_get_deflate: expected deflate MPI"
96+
else
97+
if (h5f%deflate("/A")) error stop "test_get_deflate: expected no deflate MPI"
98+
endif
99+
100+
if (.not. h5f%deflate("/noMPI")) error stop "expected deflate as dataset was written without MPI"
101+
102+
call h5f%close()
103+
104+
end subroutine test_get_deflate
105+
106+
end program

0 commit comments

Comments
 (0)