Skip to content

Commit

Permalink
Add pnetcdf test
Browse files Browse the repository at this point in the history
  • Loading branch information
uramirez8707 committed Sep 19, 2024
1 parent 44a211a commit ad538d0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test_fms/fms2_io/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LDADD = $(top_builddir)/libFMS/libFMS.la
# Build this test program.
check_PROGRAMS = test_get_is_valid test_file_appendix test_fms2_io test_atmosphere_io test_io_simple test_io_with_mask test_global_att \
test_packed_reads test_bc_restart test_get_mosaic_tile_grid test_read_ascii_file test_unlimit_compressed test_chunksizes \
test_domain_io test_compressed_writes
test_domain_io test_compressed_writes test_pnetcdf

# This is the source code for the test.
test_get_is_valid_SOURCES = test_get_is_valid.F90
Expand All @@ -53,6 +53,7 @@ test_chunksizes_SOURCES = test_chunksizes.F90
test_packed_reads_SOURCES = test_packed_reads.F90
test_compressed_writes_SOURCES = test_compressed_writes.F90
test_domain_io_SOURCES = test_domain_io.F90
test_pnetcdf_SOURCES = test_pnetcdf.F90

EXTRA_DIST = test_bc_restart.sh test_fms2_io.sh test_atmosphere_io.sh test_io_simple.sh test_global_att.sh test_io_with_mask.sh test_read_ascii_file.sh

Expand Down
72 changes: 72 additions & 0 deletions test_fms/fms2_io/test_pnetcdf.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
program test

use fms_mod, only: fms_init, fms_end
use mpp_mod
use fms2_io_mod

implicit none

integer :: baseline
integer :: one_read_broadcast
integer :: pnetcdf
type(FmsNetcdfFile_t) :: baseline_obj, one_read_broadcast_obj, pnetcdf_obj
integer :: i
integer, parameter :: nlat=360, nlon=720, np=25, ntimes=13
real :: var1(nlon, nlat, np)
integer, allocatable :: pes(:)
integer :: mpp_communicator
character(len=50) :: filename

call fms_init()
baseline = mpp_clock_id( 'Base line way of reading forcing files' )
one_read_broadcast = mpp_clock_id( 'One PE reads and broadcasts way of reading forcing files' )
pnetcdf = mpp_clock_id( 'Parallel netcdf way of reading files' )
filename = "emissions_test_file.nc"

allocate(pes(mpp_npes()))
call mpp_get_current_pelist(pes)
call mpp_declare_pelist(pes, name="all pes?", commID=mpp_communicator)

! METHOD 1
call mpp_clock_begin(baseline)
if (.not. open_file(baseline_obj, filename, "read")) &
call mpp_error(FATAL, "Unable to open the file!")

do i = 1, ntimes
call read_data(baseline_obj, "fuel", var1, unlim_dim_level=i)
enddo

call close_file(baseline_obj)
call mpp_clock_end(baseline)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! METHOD 2
call mpp_clock_begin(one_read_broadcast)
if (.not. open_file(one_read_broadcast_obj, filename, "read", pelist=pes)) &
call mpp_error(FATAL, "Unable to open the file!")

do i = 1, ntimes
call read_data(one_read_broadcast_obj, "fuel", var1, unlim_dim_level=i)
enddo

call close_file(one_read_broadcast_obj)
call mpp_clock_end(one_read_broadcast)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! METHOD 3
call mpp_clock_begin(pnetcdf)
pnetcdf_obj%use_collective = .true.
pnetcdf_obj%tile_comm = mpp_communicator
if (.not. open_file(pnetcdf_obj, filename, "read")) &
call mpp_error(FATAL, "Unable to open the file!")

do i = 1, ntimes
call read_data(pnetcdf_obj, "fuel", var1, unlim_dim_level=i)
enddo

call close_file(pnetcdf_obj)
call mpp_clock_end(pnetcdf)

call fms_end()

end program test

0 comments on commit ad538d0

Please sign in to comment.