Skip to content

Commit 353c369

Browse files
committed
unify:read/write: stride optional arg
1 parent ee3566a commit 353c369

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

src/interface.f90

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ module h5mpi
104104
interface !< write.f90
105105
module subroutine hdf_create(self, dname, dtype, mem_dims, dset_dims, &
106106
filespace_id, memspace, dset_id, dtype_id, &
107-
istart, iend, chunk_size, compact, charlen)
107+
istart, iend, stride, chunk_size, compact, charlen)
108108

109109
class(hdf5_file), intent(in) :: self
110110
character(*), intent(in) :: dname
111111
integer(HID_T), intent(in) :: dtype
112112
integer(HSIZE_T), dimension(:), intent(in) :: mem_dims, dset_dims
113113
integer(HID_T), intent(out) :: filespace_id, memspace, dset_id
114114
integer(HID_T), intent(out), optional :: dtype_id
115-
integer, intent(in), dimension(:), optional :: chunk_size, istart, iend
115+
integer, intent(in), dimension(:), optional :: chunk_size, istart, iend, stride
116116
logical, intent(in), optional :: compact
117117
integer, intent(in), optional :: charlen !< length of character scalar
118118
end subroutine
@@ -152,59 +152,59 @@ module subroutine h5write_scalar(self, dname, A, compact)
152152
logical, intent(in), optional :: compact
153153
end subroutine
154154

155-
module subroutine h5write_1d(self, dname, A, dset_dims, istart, iend, chunk_size, compact)
155+
module subroutine h5write_1d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
156156
class(hdf5_file), intent(in) :: self
157157
character(*), intent(in) :: dname
158158
class(*), intent(in) :: A(:)
159-
integer, intent(in), dimension(1), optional :: istart, iend, chunk_size, dset_dims
159+
integer, intent(in), dimension(1), optional :: chunk_size, istart, iend, stride, dset_dims
160160
logical, intent(in), optional :: compact
161161
end subroutine
162162

163-
module subroutine h5write_2d(self, dname, A, dset_dims, istart, iend, chunk_size, compact)
163+
module subroutine h5write_2d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
164164
class(hdf5_file), intent(in) :: self
165165
character(*), intent(in) :: dname
166166
class(*), intent(in) :: A(:,:)
167-
integer, intent(in), dimension(2), optional :: istart, iend, chunk_size, dset_dims
167+
integer, intent(in), dimension(2), optional :: chunk_size, istart, iend, stride, dset_dims
168168
logical, intent(in), optional :: compact
169169
end subroutine
170170

171-
module subroutine h5write_3d(self, dname, A, dset_dims, istart, iend, chunk_size, compact)
171+
module subroutine h5write_3d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
172172
class(hdf5_file), intent(in) :: self
173173
character(*), intent(in) :: dname
174174
class(*), intent(in) :: A(:,:,:)
175-
integer, intent(in), dimension(3), optional :: istart, iend, chunk_size, dset_dims
175+
integer, intent(in), dimension(3), optional :: chunk_size, istart, iend, stride, dset_dims
176176
logical, intent(in), optional :: compact
177177
end subroutine
178178

179-
module subroutine h5write_4d(self, dname, A, dset_dims, istart, iend, chunk_size, compact)
179+
module subroutine h5write_4d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
180180
class(hdf5_file), intent(in) :: self
181181
character(*), intent(in) :: dname
182182
class(*), intent(in) :: A(:,:,:,:)
183-
integer, intent(in), dimension(4), optional :: istart, iend, chunk_size, dset_dims
183+
integer, intent(in), dimension(4), optional :: chunk_size, istart, iend, stride, dset_dims
184184
logical, intent(in), optional :: compact
185185
end subroutine
186186

187-
module subroutine h5write_5d(self, dname, A, dset_dims, istart, iend, chunk_size, compact)
187+
module subroutine h5write_5d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
188188
class(hdf5_file), intent(in) :: self
189189
character(*), intent(in) :: dname
190190
class(*), intent(in) :: A(:,:,:,:,:)
191-
integer, intent(in), dimension(5), optional :: istart, iend, chunk_size, dset_dims
191+
integer, intent(in), dimension(5), optional :: chunk_size, istart, iend, stride, dset_dims
192192
logical, intent(in), optional :: compact
193193
end subroutine
194194

195-
module subroutine h5write_6d(self, dname, A, dset_dims, istart, iend, chunk_size, compact)
195+
module subroutine h5write_6d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
196196
class(hdf5_file), intent(in) :: self
197197
character(*), intent(in) :: dname
198198
class(*), intent(in) :: A(:,:,:,:,:,:)
199-
integer, intent(in), dimension(6), optional :: istart, iend, chunk_size, dset_dims
199+
integer, intent(in), dimension(6), optional :: chunk_size, istart, iend, stride, dset_dims
200200
logical, intent(in), optional :: compact
201201
end subroutine
202202

203-
module subroutine h5write_7d(self, dname, A, dset_dims, istart, iend, chunk_size, compact)
203+
module subroutine h5write_7d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
204204
class(hdf5_file), intent(in) :: self
205205
character(*), intent(in) :: dname
206206
class(*), intent(in) :: A(:,:,:,:,:,:,:)
207-
integer, intent(in), dimension(7), optional :: istart, iend, chunk_size, dset_dims
207+
integer, intent(in), dimension(7), optional :: chunk_size, istart, iend, stride, dset_dims
208208
logical, intent(in), optional :: compact
209209
end subroutine
210210

@@ -289,53 +289,53 @@ module subroutine h5read_scalar(self, dname, A)
289289
class(*), intent(inout) :: A
290290
end subroutine
291291

292-
module subroutine h5read_1d(self, dname, A, istart, iend)
292+
module subroutine h5read_1d(self, dname, A, istart, iend, stride)
293293
class(hdf5_file), intent(in) :: self
294294
character(*), intent(in) :: dname
295295
class(*), intent(inout) :: A(:)
296-
integer, intent(in), dimension(1), optional :: istart, iend
296+
integer, intent(in), dimension(1), optional :: istart, iend, stride
297297
end subroutine
298298

299-
module subroutine h5read_2d(self, dname, A, istart, iend)
299+
module subroutine h5read_2d(self, dname, A, istart, iend, stride)
300300
class(hdf5_file), intent(in) :: self
301301
character(*), intent(in) :: dname
302302
class(*), intent(inout) :: A(:,:)
303-
integer, intent(in), dimension(2), optional :: istart, iend
303+
integer, intent(in), dimension(2), optional :: istart, iend, stride
304304
end subroutine
305305

306-
module subroutine h5read_3d(self, dname, A, istart, iend)
306+
module subroutine h5read_3d(self, dname, A, istart, iend, stride)
307307
class(hdf5_file), intent(in) :: self
308308
character(*), intent(in) :: dname
309309
class(*), intent(inout) :: A(:,:,:)
310-
integer, intent(in), dimension(3), optional :: istart, iend
310+
integer, intent(in), dimension(3), optional :: istart, iend, stride
311311
end subroutine
312312

313-
module subroutine h5read_4d(self, dname, A, istart, iend)
313+
module subroutine h5read_4d(self, dname, A, istart, iend, stride)
314314
class(hdf5_file), intent(in) :: self
315315
character(*), intent(in) :: dname
316316
class(*), intent(inout) :: A(:,:,:,:)
317-
integer, intent(in), dimension(4), optional :: istart, iend
317+
integer, intent(in), dimension(4), optional :: istart, iend, stride
318318
end subroutine
319319

320-
module subroutine h5read_5d(self, dname, A, istart, iend)
320+
module subroutine h5read_5d(self, dname, A, istart, iend, stride)
321321
class(hdf5_file), intent(in) :: self
322322
character(*), intent(in) :: dname
323323
class(*), intent(inout) :: A(:,:,:,:,:)
324-
integer, intent(in), dimension(5), optional :: istart, iend
324+
integer, intent(in), dimension(5), optional :: istart, iend, stride
325325
end subroutine
326326

327-
module subroutine h5read_6d(self, dname, A, istart, iend)
327+
module subroutine h5read_6d(self, dname, A, istart, iend, stride)
328328
class(hdf5_file), intent(in) :: self
329329
character(*), intent(in) :: dname
330330
class(*), intent(inout) :: A(:,:,:,:,:,:)
331-
integer, intent(in), dimension(6), optional :: istart, iend
331+
integer, intent(in), dimension(6), optional :: istart, iend, stride
332332
end subroutine
333333

334-
module subroutine h5read_7d(self, dname, A, istart, iend)
334+
module subroutine h5read_7d(self, dname, A, istart, iend, stride)
335335
class(hdf5_file), intent(in) :: self
336336
character(*), intent(in) :: dname
337337
class(*), intent(inout) :: A(:,:,:,:,:,:,:)
338-
integer, intent(in), dimension(7), optional :: istart, iend
338+
integer, intent(in), dimension(7), optional :: istart, iend, stride
339339
end subroutine
340340

341341
end interface
@@ -538,13 +538,14 @@ module logical function is_hdf5(filename)
538538
character(*), intent(in) :: filename
539539
end function
540540

541-
module subroutine mpi_hyperslab(mem_dims, dset_dims, dset_id, filespace, memspace, istart, iend)
541+
module subroutine mpi_hyperslab(mem_dims, dset_dims, dset_id, filespace, memspace, istart, iend, stride)
542542
!! Each process defines dataset in memory and writes it to the hyperslab in the file.
543543
integer(HSIZE_T), dimension(:), intent(in) :: mem_dims, dset_dims
544544
integer(HID_T), intent(in) :: dset_id
545545
integer(HID_T), intent(inout) :: filespace, memspace
546546
integer, dimension(:), intent(in) :: istart
547547
integer, dimension(size(istart)), intent(in) :: iend
548+
integer, dimension(size(istart)), intent(in), optional :: stride
548549
end subroutine
549550

550551
module integer(HID_T) function mpi_collective(dname) result(xfer_id)

src/reader.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ call h5open_read(self, dname, dims, dset_dims, file_space_id, mem_space_id, dset
99

1010
if(self%use_mpi) then
1111
if(present(istart) .and. present(iend)) then
12-
call mpi_hyperslab(dims, dset_dims, dset_id, file_space_id, mem_space_id, istart=istart, iend=iend)
12+
call mpi_hyperslab(dims, dset_dims, dset_id, file_space_id, mem_space_id, istart=istart, iend=iend, stride=stride)
1313
endif
1414
xfer_id = mpi_collective(dname)
1515
endif

src/utils.f90

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292

293293
module procedure mpi_hyperslab
294294

295-
integer(HSIZE_T), dimension(size(mem_dims)) :: c_mem_dims, i0
295+
integer(HSIZE_T), dimension(size(mem_dims)) :: c_mem_dims, i0, istride
296296
integer(HID_T) :: dcpl
297297
integer :: ierr
298298
logical :: filters_OK
@@ -332,6 +332,9 @@
332332
i0 = istart - 1
333333
c_mem_dims = iend - i0
334334

335+
istride = 1
336+
if(present(stride)) istride = int(stride, HSIZE_T)
337+
335338
if(any(c_mem_dims /= mem_dims)) then
336339
write(stderr,*) "ERROR:h5fortran:mpi_hyperslab: memory size /= dataset size: check variable slice (index). " // &
337340
" Dset_dims:", dset_dims, "C Mem_dims", c_mem_dims
@@ -344,9 +347,9 @@
344347

345348
call h5sselect_hyperslab_f(filespace, H5S_SELECT_SET_F, &
346349
start=i0, &
350+
stride=istride, &
347351
count=c_mem_dims, &
348352
hdferr=ierr)
349-
! stride=1, & !< for now we don't stride data
350353
! block=blk !< would this help performance?
351354

352355
if (ierr/=0) error stop "g5fortran:mpi_hyperslab:h5sselect_hyperslab: " // dset_name
@@ -387,15 +390,15 @@
387390

388391
!> check for matching rank, else bad reads can occur--doesn't always crash without this check
389392
call h5ltget_dataset_ndims_f(self%file_id, dname, drank, ierr)
390-
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check: get_dataset_ndim ' // dname // ' read ' // self%filename
393+
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check:get_dataset_ndims: ' // dname // ' in ' // self%filename
391394

392395
if (drank == mrank) return
393396

394397
if (present(vector_scalar) .and. drank == 1 .and. mrank == 0) then
395398
!! check if vector of length 1
396399
call h5ltget_dataset_info_f(self%file_id, dname, dims=ddims, &
397400
type_class=type_class, type_size=type_size, errcode=ierr)
398-
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check: get_dataset_info ' // dname // ' read ' // self%filename
401+
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check:get_dataset_info ' // dname // ' in ' // self%filename
399402
if (ddims(1) == 1) then
400403
vector_scalar = .true.
401404
return

src/writer.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ end select
3333
!> create or open dataset
3434
call hdf_create(self, dname, dtype, mem_dims=mem_dims, dset_dims=dims_dset, &
3535
filespace_id=file_space_id, memspace=mem_space_id, dset_id=dset_id, &
36-
istart=istart, iend=iend, chunk_size=chunk_size, compact=compact, &
36+
istart=istart, iend=iend, stride=stride, chunk_size=chunk_size, compact=compact, &
3737
dtype_id=dtype_id, charlen=charlen)
3838

3939
if(self%use_mpi) then
4040
if(present(dset_dims)) then
41-
call mpi_hyperslab(mem_dims, dims_dset, dset_id, file_space_id, mem_space_id, istart=istart, iend=iend)
41+
call mpi_hyperslab(mem_dims, dims_dset, dset_id, file_space_id, mem_space_id, istart=istart, iend=iend, stride=stride)
4242
elseif(self%mpi_id > 0) then
4343
call h5sselect_none_f(file_space_id, ier)
4444
if(ier /= 0) error stop "ERROR:h5fortran:writer:h5sselect_none: selecting no write failed for worker. " // dname

0 commit comments

Comments
 (0)