Skip to content

Commit

Permalink
working on vard
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jul 22, 2019
1 parent 21bced8 commit 9f975e9
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/fncint/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ LDADD += -lnetcdff
AM_FCFLAGS = -I${top_builddir}/src/flib ${CPPFLAGS}

# Build the test for make check.
check_PROGRAMS = ftst_pio
check_PROGRAMS = ftst_pio ftst_pio_orig
ftst_pio_SOURCES = ftst_pio.f90
ftst_pio_orig_SOURCES = ftst_pio_orig.f90

if RUN_TESTS
# Tests will run from a bash script.
Expand Down
15 changes: 11 additions & 4 deletions tests/fncint/ftst_pio.f90
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,22 @@ program ftst_pio
if (ierr .ne. nf_noerr) call handle_err(ierr)

! Define a 2D decomposition.
dims(1) = NLAT / ntasks
dims(2) = NLON / ntasks
dims(1) = NLAT * 2 / ntasks
dims(2) = NLON * 2 / ntasks
maplen = dims(1) * dims(2)
print *, 'dims: ', dims
print *, 'maplen: ', maplen
print *, 'my_rank: ', my_rank
allocate(compdof(maplen))
allocate(data_buffer(maplen))
! Row decomposition. Recall that my_rank is 0-based, even
! in fortran. Also recall that compdof is 1-based for fortran.
do i = 1, maplen
compdof(i) = i + (my_rank - 1) * maplen
data_buffer(i) = (my_rank - 1) * 10 + i
compdof(i) = i + my_rank * maplen
!data_buffer(i) = my_rank * 10 + i
data_buffer(i) = my_rank
end do
print *, 'compdof', my_rank, compdof
ierr = nf_def_decomp(iosysid, PIO_int, dims, compdof, decompid)
if (ierr .ne. nf_noerr) call handle_err(ierr)

Expand Down
118 changes: 118 additions & 0 deletions tests/fncint/ftst_pio_orig.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
!> This is a test program for the Fortran API use of the netCDF
!! integration layer.
!!
!! @author Ed Hartnett, 7/19/19

program ftst_pio
use pio
implicit none
include 'mpif.h'
include 'netcdf.inc'

character*(*) FILE_NAME
parameter (FILE_NAME = 'ftst_pio.nc')
integer :: NDIM3 = 3, NRECS = 2, NLAT = 4, NLON = 4
character*(*) LAT_NAME, LON_NAME, REC_NAME, VAR_NAME
parameter (LAT_NAME = 'latitude', LON_NAME = 'longitude', &
REC_NAME = 'time', VAR_NAME = 'some_data_var')
integer :: my_rank, ntasks
integer :: niotasks = 1, numAggregator = 0, stride = 1, base = 0
integer :: ncid
integer, dimension(:), allocatable :: compdof
integer, dimension(:), allocatable :: data_buffer
integer, dimension(2) :: dims
integer, dimension(3) :: var_dim
type(iosystem_desc_t) :: ioSystem
type(io_desc_t) :: iodesc
integer :: maplen
integer :: decompid, iosysid
integer :: varid, i
integer :: ierr

! Set up MPI.
call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierr)
call MPI_Comm_size(MPI_COMM_WORLD, ntasks, ierr)

! These control logging in the PIO and netCDF libraries.
ierr = pio_set_log_level(3)
ierr = nf_set_log_level(2)
if (ierr .ne. nf_noerr) call handle_err(ierr)

! Define an IOSystem.
call PIO_init(my_rank, MPI_COMM_WORLD, niotasks, numAggregator, stride, &
PIO_rearr_subset, ioSystem, base=base)

! Define a 2D decomposition.
dims(1) = NLAT * 2 / ntasks
dims(2) = NLON * 2 / ntasks
maplen = dims(1) * dims(2)
print *, 'dims: ', dims
print *, 'maplen: ', maplen
print *, 'my_rank: ', my_rank
allocate(compdof(maplen))
allocate(data_buffer(maplen))
! Row decomposition. Recall that my_rank is 0-based, even
! in fortran. Also recall that compdof is 1-based for fortran.
do i = 1, maplen
compdof(i) = i + my_rank * maplen
!data_buffer(i) = my_rank * 10 + i
data_buffer(i) = my_rank
end do
print *, 'compdof', my_rank, compdof

! call PIO_initdecomp(ioSystem, PIO_int, maplen, compdof, iodesc)


! ierr = nf_def_decomp(iosysid, PIO_int, dims, compdof, decompid)
! if (ierr .ne. nf_noerr) call handle_err(ierr)

! ! Create a file.
! ierr = nf_create(FILE_NAME, 64, ncid)
! if (ierr .ne. nf_noerr) call handle_err(ierr)

! ! Define dimensions.
! ierr = nf_def_dim(ncid, LAT_NAME, NLAT, var_dim(1))
! if (ierr .ne. nf_noerr) call handle_err(ierr)
! ierr = nf_def_dim(ncid, LON_NAME, NLON, var_dim(2))
! if (ierr .ne. nf_noerr) call handle_err(ierr)
! ierr = nf_def_dim(ncid, REC_NAME, NF_UNLIMITED, var_dim(3))
! if (ierr .ne. nf_noerr) call handle_err(ierr)

! ! Define a data variable.
! ierr = nf_def_var(ncid, VAR_NAME, NF_INT, NDIM3, var_dim, varid)
! if (ierr .ne. nf_noerr) call handle_err(ierr)
! ierr = nf_enddef(ncid)
! if (ierr .ne. nf_noerr) call handle_err(ierr)

! ! Write 1st record with distributed arrays.
! ierr = nf_put_vard_int(ncid, varid, decompid, 1, data_buffer)
! if (ierr .ne. nf_noerr) call handle_err(ierr)

! ! Close the file.
! ierr = nf_close(ncid)
! if (ierr .ne. nf_noerr) call handle_err(ierr)

! ! Free resources.
! ierr = nf_free_decomp(decompid)
! if (ierr .ne. nf_noerr) call handle_err(ierr)
deallocate(compdof)
deallocate(data_buffer)
! call PIO_freedecomp(ioSystem, iodesc)
call pio_finalize(ioSystem, ierr)

! We're done!
call MPI_Finalize(ierr)
if (my_rank .eq. 0) then
print *, '*** SUCCESS running ftst_pio!'
endif
end program ftst_pio

subroutine handle_err(errcode)
implicit none
include 'netcdf.inc'
integer errcode

print *, 'Error: ', nf_strerror(errcode)
stop 2
end subroutine handle_err
3 changes: 2 additions & 1 deletion tests/fncint/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ trap exit INT TERM

printf 'running Fortran tests for PIO netCDF integration...\n'

PIO_TESTS='ftst_pio'
#PIO_TESTS='ftst_pio_orig ftst_pio'
PIO_TESTS='ftst_pio_orig'

success1=true
for TEST in $PIO_TESTS
Expand Down

0 comments on commit 9f975e9

Please sign in to comment.