@@ -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,
0 commit comments