@@ -6,10 +6,9 @@ program test_deflate
6
6
7
7
use , intrinsic :: iso_fortran_env, only: int32, int64, real32, real64, stderr= >error_unit
8
8
9
- use hdf5, only : H5D_CHUNKED_F, H5D_CONTIGUOUS_F, hsize_t
10
9
use mpi, only : mpi_init, mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD
11
10
12
- use h5mpi, only: hdf5_file, HSIZE_T, has_parallel_compression
11
+ use h5mpi, only: hdf5_file, HSIZE_T
13
12
14
13
implicit none (type, external )
15
14
@@ -18,58 +17,42 @@ program test_deflate
18
17
character (* ), parameter :: fn1= ' deflate1.h5' , fn2= ' deflate2.h5' , fn3= ' deflate3.h5'
19
18
integer , parameter :: N(2 ) = [50 , 1000 ], &
20
19
MIN_COMP = 2 ! < lots of CPUs, smaller arrays => poorer compression
21
- integer :: ierr, mpi_id
20
+ integer :: ierr, mpi_id, Nmpi
22
21
23
22
24
23
call mpi_init(ierr)
25
24
if (ierr /= 0 ) error stop " mpi_init"
26
25
26
+ call mpi_comm_size(MPI_COMM_WORLD, Nmpi, ierr)
27
+ if (ierr/= 0 ) error stop " mpi_comm_size"
27
28
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
28
29
if (ierr/= 0 ) error stop " mpi_comm_rank"
29
30
30
- call test_write_deflate(fn1, N)
31
+ call test_write_deflate(fn1, N, mpi_id, Nmpi )
31
32
if (mpi_id== 0 ) print * ,' OK: HDF5 write deflate'
32
33
33
- call test_read_deflate_props(fn1, N)
34
- if (mpi_id== 0 ) print * ,' OK: HDF5 read deflate properties'
35
-
36
34
call test_deflate_whole(fn2, N)
37
35
if (mpi_id== 0 ) print * ,' OK: HDF5 compress whole'
38
36
39
37
call test_deflate_slice(fn3, N)
40
38
if (mpi_id== 0 ) print * ,' OK: HDF5 compress slice'
41
39
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
-
48
40
call mpi_finalize(ierr)
49
41
if (ierr /= 0 ) error stop " mpi_finalize"
50
42
51
43
contains
52
44
53
- subroutine test_write_deflate (fn , N )
45
+ subroutine test_write_deflate (fn , N , mpi_id , Nmpi )
54
46
55
47
character (* ), intent (in ) :: fn
56
- integer , intent (in ) :: N(2 )
48
+ integer , intent (in ) :: N(2 ), mpi_id, Nmpi
57
49
58
50
type (hdf5_file) :: h5f
59
-
60
51
integer (HSIZE_T) :: i0(2 ), i1(2 ), dx2
61
- integer :: Nmpi, mpi_id
62
-
63
52
real (real32), allocatable :: A(:,:)
64
-
65
53
logical :: debug = .false.
66
54
67
55
! > 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
-
73
56
if (mpi_id == 0 ) then
74
57
if (Nmpi > 1 .and. (modulo (N(2 ), Nmpi) /= 0 .or. Nmpi > N(2 ))) then
75
58
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)
95
78
call h5f% write (' /A' , A, N, istart= i0, iend= i1, chunk_size= [5 , 50 ])
96
79
call h5f% close ()
97
80
81
+ deallocate (A)
82
+
98
83
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
100
87
call h5f% open (fn, action= ' a' , comp_lvl= 1 , mpi= .false. )
101
88
102
89
call h5f% write (' /small_contig' , A(:4 ,:4 ))
103
90
! ! not compressed because too small
104
91
105
- call h5f% write (' /noMPI' , A(:,:) )
92
+ call h5f% write (' /noMPI' , A)
106
93
! ! write without MPI, with compression
107
94
108
95
call h5f% close ()
@@ -111,51 +98,6 @@ subroutine test_write_deflate(fn, N)
111
98
end subroutine test_write_deflate
112
99
113
100
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
-
159
101
subroutine test_deflate_whole (fn , N )
160
102
161
103
character (* ), intent (in ) :: fn
@@ -271,26 +213,4 @@ subroutine test_deflate_slice(fn, N)
271
213
end subroutine test_deflate_slice
272
214
273
215
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
-
296
216
end program
0 commit comments