Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: nf90mpi_Inq_buffer_size #111

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/binding/f90/getput_var.m4
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ NBVAR(bput, 7, EightByteInt, integer, int8, `:,:,:,:,:,:,:', INTENTV)
integer (kind=MPI_OFFSET_KIND), intent(out) :: buf_size
integer :: nf90mpi_inq_buffer_size

nf90mpi_inq_buffer_size = nfmpi_inq_buffer_usage(ncid, buf_size)
nf90mpi_inq_buffer_size = nfmpi_inq_buffer_size(ncid, buf_size)
end function nf90mpi_inq_buffer_size

function nf90mpi_buffer_detach(ncid)
Expand Down
85 changes: 76 additions & 9 deletions test/nonblocking/test_bputf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ subroutine check(err, message)
use mpi
use pnetcdf
implicit none
integer err
integer err, ierr
character(len=*) message

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

Expand All @@ -23,17 +23,19 @@ program main
use pnetcdf
implicit none

logical verbose
logical verbose, using_bb
integer i, j, ncid, varid, err, ierr, rank, nprocs, info
integer no_err, cmode, get_args
integer no_err, cmode, get_args, idx
integer dimid(2), req(2), status(2)
integer(kind=MPI_OFFSET_KIND) start(2)
integer(kind=MPI_OFFSET_KIND) count(2)
integer(kind=MPI_OFFSET_KIND) stride(2)
integer(kind=MPI_OFFSET_KIND) imap(2)
integer(kind=MPI_OFFSET_KIND) bufsize
integer(kind=MPI_OFFSET_KIND) bufsize, inq_bufsize
integer(kind=MPI_OFFSET_KIND) usage, acc_usage
real var(6,4)
character(len=256) :: filename, cmd, msg
character(len=512) :: hints

call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
Expand All @@ -54,6 +56,12 @@ program main
' is designed to run on 1 process'
endif

call getenv("PNETCDF_HINTS", hints)
idx = index(hints, "nc_burst_buf=enable")

using_bb = .FALSE.
if (idx > 0) using_bb = .TRUE.

call MPI_Info_create(info, ierr)
! call MPI_Info_set(info, "romio_pvfs2_posix_write","enable",ierr)

Expand Down Expand Up @@ -90,10 +98,29 @@ program main
enddo
enddo

! bufsize must be max of data type converted before and after
bufsize = 4*6*8
err = nf90mpi_buffer_attach(ncid, bufsize)
call check(err, 'Error at nf90mpi_buffer_attach ')
if (.NOT. using_bb) then
! bufsize must be max of data type converted before and after
bufsize = 4*6*8
acc_usage = 0
err = nf90mpi_buffer_attach(ncid, bufsize)
call check(err, 'Error at nf90mpi_buffer_attach ')

err = nf90mpi_inq_buffer_size(ncid, inq_bufsize)
call check(err, 'Error at nf90mpi_inq_buffer_size ')

if (inq_bufsize .NE. bufsize) then
print*,"Error: expect bufsize ",bufsize,"but got ",inq_bufsize
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if

err = nf90mpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nf90mpi_inq_buffer_usage ')

if (usage .NE. acc_usage) then
print*,"Error: expect buf usage ",acc_usage," but got ",usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

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

acc_usage = acc_usage + count(1) * count(2) * 8

if (.NOT. using_bb) then
err = nf90mpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nf90mpi_inq_buffer_usage ')

if (usage .NE. acc_usage) then
print*,"Error: expect buf usage ",acc_usage," but got ",usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

! write the second two columns of the NC variable in the matrix transposed way
start(1) = 3
start(2) = 1
err = nf90mpi_bput_var(ncid, varid, var(1:,3:), req(2), start, count, &
stride, imap)
call check(err, 'Error at nf90mpi_bput_var ')

acc_usage = acc_usage + count(1) * count(2) * 8

if (.NOT. using_bb) then
err = nf90mpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nf90mpi_inq_buffer_usage ')

if (usage .NE. acc_usage) then
print*,"Error: expect buf usage ",acc_usage," but got ",usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

err = nf90mpi_wait_all(ncid, 2, req, status)
call check(err, 'Error at nf90mpi_wait_all ')

if (.NOT. using_bb) then
err = nf90mpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nf90mpi_inq_buffer_usage ')

if (usage .NE. 0) then
print*,"Error: expect buf usage 0 but got ",usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

! check each bput status
do i = 1, 2
if (status(i) .ne. NF90_NOERR) then
Expand All @@ -135,6 +196,12 @@ program main
err = nf90mpi_buffer_detach(ncid)
call check(err, 'Error at nf90mpi_buffer_detach ')

err = nf90mpi_inq_buffer_size(ncid, inq_bufsize)
if (err .NE. NF90_ENULLABUF) then
print*,"Error: unexpected error code ",err
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if

! the output from command "ncmpidump -v var test.nc" should be:
! var =
! 50, 56, 62, 68,
Expand Down
81 changes: 76 additions & 5 deletions test/nonblocking/test_bputf77.f
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ subroutine check(err, message)
implicit none
include "mpif.h"
include "pnetcdf.inc"
integer err
integer err, ierr
character message*(*)

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

Expand All @@ -34,17 +34,19 @@ program main
include "mpif.h"
include "pnetcdf.inc"

logical verbose
logical verbose, using_bb
integer i, j, ncid, varid, err, ierr, rank, nprocs, info
integer no_err, cmode, get_args, XTRIM
integer no_err, cmode, get_args, XTRIM, idx
integer dimid(2), req(2), status(2)
integer*8 start(2)
integer*8 count(2)
integer*8 stride(2)
integer*8 imap(2)
integer*8 bufsize, dim_size
integer*8 dim_size, bufsize, inq_bufsize
real var(6,4)
character*256 filename, cmd, msg
integer*8 usage, acc_usage
character*512 hints

call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
Expand All @@ -66,6 +68,12 @@ program main
+ ' is designed to run on 1 process'
endif

call getenv("PNETCDF_HINTS", hints)
idx = index(hints, "nc_burst_buf=enable")

using_bb = .FALSE.
if (idx > 0) using_bb = .TRUE.

call MPI_Info_create(info, ierr)
! call MPI_Info_set(info, "romio_pvfs2_posix_write","enable",ierr)

Expand Down Expand Up @@ -106,9 +114,30 @@ program main

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

if (.NOT. using_bb) then
err = nfmpi_inq_buffer_size(ncid, inq_bufsize)
call check(err, 'Error at nfmpi_inq_buffer_size ')

if (inq_bufsize .NE. bufsize) then
print*,"Error: expect bufsize ",bufsize,"but got ",
+ inq_bufsize
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if

err = nfmpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nfmpi_inq_buffer_usage ')

if (.NOT. using_bb .AND. usage .NE. acc_usage) then
print*,"Error: expect buf usage ",acc_usage," but got ",
+ usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

! write var to the NC variable in the matrix transposed way
count(1) = 2
count(2) = 6
Expand All @@ -129,16 +158,52 @@ program main
+ imap, var(1,1), req(1))
call check(err, 'Error at nfmpi_bput_varm_real ')

acc_usage = acc_usage + count(1) * count(2) * 8

if (.NOT. using_bb) then
err = nfmpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nfmpi_inq_buffer_usage ')

if (usage .NE. acc_usage) then
print*,"Error: expect buf usage ",acc_usage," but got ",
+ usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

! write the second two columns of the NC variable in the matrix transposed way
start(1) = 3
start(2) = 1
err = nfmpi_bput_varm_real(ncid, varid, start, count, stride,
+ imap, var(1,3), req(2))
call check(err, 'Error at nfmpi_bput_varm_real ')

acc_usage = acc_usage + count(1) * count(2) * 8

if (.NOT. using_bb) then
err = nfmpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nfmpi_inq_buffer_usage ')

if (usage .NE. acc_usage) then
print*,"Error: expect buf usage ",acc_usage," but got ",
+ usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

err = nfmpi_wait_all(ncid, 2, req, status)
call check(err, 'Error at nfmpi_wait_all ')

if (.NOT. using_bb) then
err = nfmpi_inq_buffer_usage(ncid, usage)
call check(err, 'Error at nfmpi_inq_buffer_usage ')

if (usage .NE. 0) then
print*,"Error: expect buf usage 0 but got ",usage
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if
end if

! check each bput status
do i = 1, 2
if (status(i) .ne. NF_NOERR) then
Expand All @@ -149,6 +214,12 @@ program main
err = nfmpi_buffer_detach(ncid)
call check(err, 'Error at nfmpi_buffer_detach ')

err = nfmpi_inq_buffer_size(ncid, inq_bufsize)
if (err .NE. NF_ENULLABUF) then
print*,"Error: unexpected error code ",err
call MPI_Abort(MPI_COMM_WORLD, -1, ierr)
end if

! the output from command "ncmpidump -v var test.nc" should be:
! var =
! 50, 56, 62, 68,
Expand Down