f90tst_parallel2.f90 (netcdf-fortran-4.4.4) | : | f90tst_parallel2.f90 (netcdf-fortran-4.4.5) | ||
---|---|---|---|---|
skipping to change at line 43 | skipping to change at line 43 | |||
! _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | ! _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |||
! 2, _, 2, _, 2, _, 2, _, 3, _, 3, _, 3, _, 3, _, | ! 2, _, 2, _, 2, _, 2, _, 3, _, 3, _, 3, _, 3, _, | |||
! _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | ! _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |||
! 0, _, 0, _, 0, _, 0, _, 0, _, 0, _, 0, _, 0, _, | ! 0, _, 0, _, 0, _, 0, _, 0, _, 0, _, 0, _, 0, _, | |||
! _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ; | ! _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ; | |||
! } | ! } | |||
! $Id: f90tst_parallel2.f90,v 1.4 2010/05/25 13:53:04 ed Exp $ | ! $Id: f90tst_parallel2.f90,v 1.4 2010/05/25 13:53:04 ed Exp $ | |||
program f90tst_parallel | program f90tst_parallel | |||
use typeSizes | ||||
use netcdf | use netcdf | |||
implicit none | implicit none | |||
include 'mpif.h' | include 'mpif.h' | |||
! This is the name of the data file we will create. | ||||
character (len = *), parameter :: FILE_NAME = "f90tst_parallel2.nc" | ||||
integer, parameter :: MAX_DIMS = 2 | ||||
integer, parameter :: NX = 16, NY = 16 | ||||
integer, parameter :: NUM_PROC = 4 | ||||
integer :: ncid, varid, dimids(MAX_DIMS) | ||||
integer :: x_dimid, y_dimid | ||||
integer :: data_out(NY / 4, NX / 4), data_in(NY / 4, NX / 4) | ||||
integer :: mode_flag | integer :: mode_flag | |||
integer :: nvars, ngatts, ndims, unlimdimid, file_format | ||||
integer :: x, y | ||||
integer :: p, my_rank, ierr | integer :: p, my_rank, ierr | |||
integer :: start(MAX_DIMS), count(MAX_DIMS), stride(MAX_DIMS) | ||||
call MPI_Init(ierr) | call MPI_Init(ierr) | |||
call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierr) | call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierr) | |||
call MPI_Comm_size(MPI_COMM_WORLD, p, ierr) | call MPI_Comm_size(MPI_COMM_WORLD, p, ierr) | |||
if (my_rank .eq. 0) then | if (my_rank .eq. 0) then | |||
print *, ' ' | print *, ' ' | |||
print *, '*** Testing netCDF-4 parallel I/O with strided access.' | print *, '*** Testing netCDF-4 parallel I/O with strided access.' | |||
endif | endif | |||
! There must be 4 procs for this test. | ! There must be 4 procs for this test. | |||
if (p .ne. 4) then | if (p .ne. 4) then | |||
print *, 'Sorry, this test program must be run on four processors.' | print *, 'Sorry, this test program must be run on four processors.' | |||
stop 2 | stop 2 | |||
endif | endif | |||
#ifdef NF_HAS_PNETCDF | ||||
mode_flag = IOR(nf90_clobber, nf90_mpiio) | ||||
call parallel_io(mode_flag) | ||||
#endif | ||||
#ifdef NF_HAS_PARALLEL4 | ||||
mode_flag = IOR(nf90_netcdf4, nf90_classic_model) | ||||
mode_flag = IOR(mode_flag, nf90_mpiposix) | ||||
mode_flag = IOR(mode_flag, nf90_clobber) | ||||
call parallel_io(mode_flag) | ||||
#endif | ||||
call MPI_Finalize(ierr) | ||||
if (my_rank .eq. 0) print *,'*** SUCCESS!' | ||||
contains | ||||
! This subroutine handles errors by printing an error message and | ||||
! exiting with a non-zero status. | ||||
subroutine handle_err(errcode) | ||||
use netcdf | ||||
implicit none | ||||
integer, intent(in) :: errcode | ||||
if(errcode /= nf90_noerr) then | ||||
print *, 'Error: ', trim(nf90_strerror(errcode)) | ||||
stop 5 | ||||
endif | ||||
end subroutine handle_err | ||||
subroutine parallel_io(mode_flag) | ||||
use typeSizes | ||||
use netcdf | ||||
implicit none | ||||
include 'mpif.h' | ||||
integer :: mode_flag | ||||
! This is the name of the data file we will create. | ||||
character (len = *), parameter :: FILE_NAME = "f90tst_parallel2.nc" | ||||
integer, parameter :: MAX_DIMS = 2 | ||||
integer, parameter :: NX = 16, NY = 16 | ||||
integer, parameter :: NUM_PROC = 4 | ||||
integer :: ncid, varid, dimids(MAX_DIMS) | ||||
integer :: x_dimid, y_dimid | ||||
integer :: data_out(NY / 4, NX / 4), data_in(NY / 4, NX / 4) | ||||
integer :: nvars, ngatts, ndims, unlimdimid, file_format | ||||
integer :: x, y | ||||
integer :: my_rank, ierr | ||||
integer :: start(MAX_DIMS), count(MAX_DIMS), stride(MAX_DIMS) | ||||
call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierr) | ||||
! Create some pretend data. | ! Create some pretend data. | |||
do x = 1, NX / 4 | do x = 1, NX / 4 | |||
do y = 1, NY / 4 | do y = 1, NY / 4 | |||
data_out(y, x) = my_rank | data_out(y, x) = my_rank | |||
end do | end do | |||
end do | end do | |||
! Create the netCDF file. | ! Create the netCDF file. | |||
mode_flag = IOR(nf90_netcdf4, nf90_classic_model) | ||||
mode_flag = IOR(mode_flag, nf90_mpiposix) | ||||
call handle_err(nf90_create(FILE_NAME, mode_flag, ncid, comm = MPI_COMM_WORLD, & | call handle_err(nf90_create(FILE_NAME, mode_flag, ncid, comm = MPI_COMM_WORLD, & | |||
info = MPI_INFO_NULL)) | info = MPI_INFO_NULL)) | |||
! Define the dimensions. | ! Define the dimensions. | |||
call handle_err(nf90_def_dim(ncid, "x", NX, x_dimid)) | call handle_err(nf90_def_dim(ncid, "x", NX, x_dimid)) | |||
call handle_err(nf90_def_dim(ncid, "y", NY, y_dimid)) | call handle_err(nf90_def_dim(ncid, "y", NY, y_dimid)) | |||
dimids = (/ y_dimid, x_dimid /) | dimids = (/ y_dimid, x_dimid /) | |||
! Define the variable. | ! Define the variable. | |||
call handle_err(nf90_def_var(ncid, "data", NF90_INT, dimids, varid)) | call handle_err(nf90_def_var(ncid, "data", NF90_INT, dimids, varid)) | |||
skipping to change at line 129 | skipping to change at line 168 | |||
! Close the file. | ! Close the file. | |||
call handle_err(nf90_close(ncid)) | call handle_err(nf90_close(ncid)) | |||
! Reopen the file. | ! Reopen the file. | |||
call handle_err(nf90_open(FILE_NAME, IOR(nf90_nowrite, nf90_mpiposix), ncid, & | call handle_err(nf90_open(FILE_NAME, IOR(nf90_nowrite, nf90_mpiposix), ncid, & | |||
comm = MPI_COMM_WORLD, info = MPI_INFO_NULL)) | comm = MPI_COMM_WORLD, info = MPI_INFO_NULL)) | |||
! Check some stuff out. | ! Check some stuff out. | |||
call handle_err(nf90_inquire(ncid, ndims, nvars, ngatts, unlimdimid, file_form at)) | call handle_err(nf90_inquire(ncid, ndims, nvars, ngatts, unlimdimid, file_form at)) | |||
if (ndims /= 2 .or. nvars /= 1 .or. ngatts /= 0 .or. unlimdimid /= -1 .or. & | if (ndims /= 2 .or. nvars /= 1 .or. ngatts /= 0 .or. unlimdimid /= -1) stop 3 | |||
file_format /= nf90_format_netcdf4_classic) stop 3 | ||||
if (IAND(mode_flag, nf90_netcdf4) .GT. 0) then | ||||
if (file_format /= nf90_format_netcdf4_classic) stop 4 | ||||
else | ||||
if (file_format /= nf90_format_classic) stop 5 | ||||
endif | ||||
! Set collective access on this variable. This will cause all | ! Set collective access on this variable. This will cause all | |||
! reads/writes to happen together on every processor. Fairly | ! reads/writes to happen together on every processor. Fairly | |||
! pointless, in this contexct, but I want to at least call this | ! pointless, in this contexct, but I want to at least call this | |||
! function once in my testing. | ! function once in my testing. | |||
call handle_err(nf90_var_par_access(ncid, varid, nf90_collective)) | call handle_err(nf90_var_par_access(ncid, varid, nf90_collective)) | |||
! Read this processor's data. | ! Read this processor's data. | |||
call handle_err(nf90_get_var(ncid, varid, data_in, start = start, count = coun t, & | call handle_err(nf90_get_var(ncid, varid, data_in, start = start, count = coun t, & | |||
stride = stride)) | stride = stride)) | |||
! Check the data. | ! Check the data. | |||
do x = 1, NX / 4 | do x = 1, NX / 4 | |||
do y = 1, NY / 4 | do y = 1, NY / 4 | |||
if (data_in(y, x) .ne. my_rank) stop 4 | if (data_in(y, x) .ne. my_rank) stop 6 | |||
end do | end do | |||
end do | end do | |||
! Close the file. | ! Close the file. | |||
call handle_err(nf90_close(ncid)) | call handle_err(nf90_close(ncid)) | |||
end subroutine parallel_io | ||||
call MPI_Finalize(ierr) | ||||
if (my_rank .eq. 0) print *,'*** SUCCESS!' | ||||
contains | ||||
! This subroutine handles errors by printing an error message and | ||||
! exiting with a non-zero status. | ||||
subroutine handle_err(errcode) | ||||
use netcdf | ||||
implicit none | ||||
integer, intent(in) :: errcode | ||||
if(errcode /= nf90_noerr) then | ||||
print *, 'Error: ', trim(nf90_strerror(errcode)) | ||||
stop 5 | ||||
endif | ||||
end subroutine handle_err | ||||
end program f90tst_parallel | end program f90tst_parallel | |||
End of changes. 10 change blocks. | ||||
35 lines changed or deleted | 63 lines changed or added |