Skip to content

Commit 94ce438

Browse files
committed
add tests of inq_buffer_usage and inq_buffer_size
1 parent 01b15a5 commit 94ce438

File tree

2 files changed

+152
-14
lines changed

2 files changed

+152
-14
lines changed

test/nonblocking/test_bputf.f90

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ subroutine check(err, message)
88
use mpi
99
use pnetcdf
1010
implicit none
11-
integer err
11+
integer err, ierr
1212
character(len=*) message
1313

1414
! It is a good idea to check returned value for possible error
1515
if (err .NE. NF90_NOERR) then
1616
write(6,*) trim(message), trim(nf90mpi_strerror(err))
17-
call MPI_Abort(MPI_COMM_WORLD, -1, err)
17+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
1818
end if
1919
end subroutine check
2020

@@ -23,17 +23,19 @@ program main
2323
use pnetcdf
2424
implicit none
2525

26-
logical verbose
26+
logical verbose, using_bb
2727
integer i, j, ncid, varid, err, ierr, rank, nprocs, info
28-
integer no_err, cmode, get_args
28+
integer no_err, cmode, get_args, idx
2929
integer dimid(2), req(2), status(2)
3030
integer(kind=MPI_OFFSET_KIND) start(2)
3131
integer(kind=MPI_OFFSET_KIND) count(2)
3232
integer(kind=MPI_OFFSET_KIND) stride(2)
3333
integer(kind=MPI_OFFSET_KIND) imap(2)
34-
integer(kind=MPI_OFFSET_KIND) bufsize
34+
integer(kind=MPI_OFFSET_KIND) bufsize, inq_bufsize
35+
integer(kind=MPI_OFFSET_KIND) usage, acc_usage
3536
real var(6,4)
3637
character(len=256) :: filename, cmd, msg
38+
character(len=512) :: hints
3739

3840
call MPI_INIT(ierr)
3941
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
@@ -54,6 +56,12 @@ program main
5456
' is designed to run on 1 process'
5557
endif
5658

59+
call getenv("PNETCDF_HINTS", hints)
60+
idx = index(hints, "nc_burst_buf=enable")
61+
62+
using_bb = .FALSE.
63+
if (idx > 0) using_bb = .TRUE.
64+
5765
call MPI_Info_create(info, ierr)
5866
! call MPI_Info_set(info, "romio_pvfs2_posix_write","enable",ierr)
5967

@@ -90,10 +98,29 @@ program main
9098
enddo
9199
enddo
92100

93-
! bufsize must be max of data type converted before and after
94-
bufsize = 4*6*8
95-
err = nf90mpi_buffer_attach(ncid, bufsize)
96-
call check(err, 'Error at nf90mpi_buffer_attach ')
101+
if (.NOT. using_bb) then
102+
! bufsize must be max of data type converted before and after
103+
bufsize = 4*6*8
104+
acc_usage = 0
105+
err = nf90mpi_buffer_attach(ncid, bufsize)
106+
call check(err, 'Error at nf90mpi_buffer_attach ')
107+
108+
err = nf90mpi_inq_buffer_size(ncid, inq_bufsize)
109+
call check(err, 'Error at nf90mpi_inq_buffer_size ')
110+
111+
if (inq_bufsize .NE. bufsize) then
112+
print*,"Error: expect bufsize ",bufsize,"but got ",inq_bufsize
113+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
114+
end if
115+
116+
err = nf90mpi_inq_buffer_usage(ncid, usage)
117+
call check(err, 'Error at nf90mpi_inq_buffer_usage ')
118+
119+
if (usage .NE. acc_usage) then
120+
print*,"Error: expect buf usage ",acc_usage," but got ",usage
121+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
122+
end if
123+
end if
97124

98125
! write var to the NC variable in the matrix transposed way
99126
count(1) = 2
@@ -115,16 +142,50 @@ program main
115142
stride, imap)
116143
call check(err, 'Error at nf90mpi_bput_var ')
117144

145+
acc_usage = acc_usage + count(1) * count(2) * 8
146+
147+
if (.NOT. using_bb) then
148+
err = nf90mpi_inq_buffer_usage(ncid, usage)
149+
call check(err, 'Error at nf90mpi_inq_buffer_usage ')
150+
151+
if (usage .NE. acc_usage) then
152+
print*,"Error: expect buf usage ",acc_usage," but got ",usage
153+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
154+
end if
155+
end if
156+
118157
! write the second two columns of the NC variable in the matrix transposed way
119158
start(1) = 3
120159
start(2) = 1
121160
err = nf90mpi_bput_var(ncid, varid, var(1:,3:), req(2), start, count, &
122161
stride, imap)
123162
call check(err, 'Error at nf90mpi_bput_var ')
124163

164+
acc_usage = acc_usage + count(1) * count(2) * 8
165+
166+
if (.NOT. using_bb) then
167+
err = nf90mpi_inq_buffer_usage(ncid, usage)
168+
call check(err, 'Error at nf90mpi_inq_buffer_usage ')
169+
170+
if (usage .NE. acc_usage) then
171+
print*,"Error: expect buf usage ",acc_usage," but got ",usage
172+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
173+
end if
174+
end if
175+
125176
err = nf90mpi_wait_all(ncid, 2, req, status)
126177
call check(err, 'Error at nf90mpi_wait_all ')
127178

179+
if (.NOT. using_bb) then
180+
err = nf90mpi_inq_buffer_usage(ncid, usage)
181+
call check(err, 'Error at nf90mpi_inq_buffer_usage ')
182+
183+
if (usage .NE. 0) then
184+
print*,"Error: expect buf usage 0 but got ",usage
185+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
186+
end if
187+
end if
188+
128189
! check each bput status
129190
do i = 1, 2
130191
if (status(i) .ne. NF90_NOERR) then
@@ -135,6 +196,12 @@ program main
135196
err = nf90mpi_buffer_detach(ncid)
136197
call check(err, 'Error at nf90mpi_buffer_detach ')
137198

199+
err = nf90mpi_inq_buffer_size(ncid, inq_bufsize)
200+
if (err .NE. NF90_ENULLABUF) then
201+
print*,"Error: unexpected error code ",err
202+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
203+
end if
204+
138205
! the output from command "ncmpidump -v var test.nc" should be:
139206
! var =
140207
! 50, 56, 62, 68,

test/nonblocking/test_bputf77.f

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ subroutine check(err, message)
1919
implicit none
2020
include "mpif.h"
2121
include "pnetcdf.inc"
22-
integer err
22+
integer err, ierr
2323
character message*(*)
2424

2525
! It is a good idea to check returned value for possible error
2626
if (err .NE. NF_NOERR) then
2727
write(6,*) message//' '//nfmpi_strerror(err)
28-
call MPI_Abort(MPI_COMM_WORLD, -1, err)
28+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
2929
endif
3030
end ! subroutine check
3131

@@ -34,17 +34,19 @@ program main
3434
include "mpif.h"
3535
include "pnetcdf.inc"
3636

37-
logical verbose
37+
logical verbose, using_bb
3838
integer i, j, ncid, varid, err, ierr, rank, nprocs, info
39-
integer no_err, cmode, get_args, XTRIM
39+
integer no_err, cmode, get_args, XTRIM, idx
4040
integer dimid(2), req(2), status(2)
4141
integer*8 start(2)
4242
integer*8 count(2)
4343
integer*8 stride(2)
4444
integer*8 imap(2)
45-
integer*8 bufsize, dim_size
45+
integer*8 dim_size, bufsize, inq_bufsize
4646
real var(6,4)
4747
character*256 filename, cmd, msg
48+
integer*8 usage, acc_usage
49+
character*512 hints
4850

4951
call MPI_INIT(ierr)
5052
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
@@ -66,6 +68,12 @@ program main
6668
+ ' is designed to run on 1 process'
6769
endif
6870

71+
call getenv("PNETCDF_HINTS", hints)
72+
idx = index(hints, "nc_burst_buf=enable")
73+
74+
using_bb = .FALSE.
75+
if (idx > 0) using_bb = .TRUE.
76+
6977
call MPI_Info_create(info, ierr)
7078
! call MPI_Info_set(info, "romio_pvfs2_posix_write","enable",ierr)
7179

@@ -106,9 +114,30 @@ program main
106114

107115
! bufsize must be max of data type converted before and after
108116
bufsize = 4*6*8
117+
acc_usage = 0
109118
err = nfmpi_buffer_attach(ncid, bufsize)
110119
call check(err, 'Error at nfmpi_buffer_attach ')
111120

121+
if (.NOT. using_bb) then
122+
err = nfmpi_inq_buffer_size(ncid, inq_bufsize)
123+
call check(err, 'Error at nfmpi_inq_buffer_size ')
124+
125+
if (inq_bufsize .NE. bufsize) then
126+
print*,"Error: expect bufsize ",bufsize,"but got ",
127+
+ inq_bufsize
128+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
129+
end if
130+
131+
err = nfmpi_inq_buffer_usage(ncid, usage)
132+
call check(err, 'Error at nfmpi_inq_buffer_usage ')
133+
134+
if (.NOT. using_bb .AND. usage .NE. acc_usage) then
135+
print*,"Error: expect buf usage ",acc_usage," but got ",
136+
+ usage
137+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
138+
end if
139+
end if
140+
112141
! write var to the NC variable in the matrix transposed way
113142
count(1) = 2
114143
count(2) = 6
@@ -129,16 +158,52 @@ program main
129158
+ imap, var(1,1), req(1))
130159
call check(err, 'Error at nfmpi_bput_varm_real ')
131160

161+
acc_usage = acc_usage + count(1) * count(2) * 8
162+
163+
if (.NOT. using_bb) then
164+
err = nfmpi_inq_buffer_usage(ncid, usage)
165+
call check(err, 'Error at nfmpi_inq_buffer_usage ')
166+
167+
if (usage .NE. acc_usage) then
168+
print*,"Error: expect buf usage ",acc_usage," but got ",
169+
+ usage
170+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
171+
end if
172+
end if
173+
132174
! write the second two columns of the NC variable in the matrix transposed way
133175
start(1) = 3
134176
start(2) = 1
135177
err = nfmpi_bput_varm_real(ncid, varid, start, count, stride,
136178
+ imap, var(1,3), req(2))
137179
call check(err, 'Error at nfmpi_bput_varm_real ')
138180

181+
acc_usage = acc_usage + count(1) * count(2) * 8
182+
183+
if (.NOT. using_bb) then
184+
err = nfmpi_inq_buffer_usage(ncid, usage)
185+
call check(err, 'Error at nfmpi_inq_buffer_usage ')
186+
187+
if (usage .NE. acc_usage) then
188+
print*,"Error: expect buf usage ",acc_usage," but got ",
189+
+ usage
190+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
191+
end if
192+
end if
193+
139194
err = nfmpi_wait_all(ncid, 2, req, status)
140195
call check(err, 'Error at nfmpi_wait_all ')
141196

197+
if (.NOT. using_bb) then
198+
err = nfmpi_inq_buffer_usage(ncid, usage)
199+
call check(err, 'Error at nfmpi_inq_buffer_usage ')
200+
201+
if (usage .NE. 0) then
202+
print*,"Error: expect buf usage 0 but got ",usage
203+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
204+
end if
205+
end if
206+
142207
! check each bput status
143208
do i = 1, 2
144209
if (status(i) .ne. NF_NOERR) then
@@ -149,6 +214,12 @@ program main
149214
err = nfmpi_buffer_detach(ncid)
150215
call check(err, 'Error at nfmpi_buffer_detach ')
151216

217+
err = nfmpi_inq_buffer_size(ncid, inq_bufsize)
218+
if (err .NE. NF_ENULLABUF) then
219+
print*,"Error: unexpected error code ",err
220+
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
221+
end if
222+
152223
! the output from command "ncmpidump -v var test.nc" should be:
153224
! var =
154225
! 50, 56, 62, 68,

0 commit comments

Comments
 (0)