When I try to construct a simple array and write to a output file using MPIIO, the output file is very large and not correct. The simple array 'buff' is 2 * 3 and every element equals to 1. I first create the subarray filetype which is 1 * 1, and then create a new output file 'out.dat'. I use set_view function and write_all to write this buff array. I compile this and run it use 6 cores so that one core write one element. I expect that I can get a 'out.dat' and a 2*3 array with value 1.
I successfully compile and run this code, and the results are all 0 and the size is very large.
program test
use mpi
implicit none
integer::rank,nproc,ierr,buffsize,status(MPI_STATUS_SIZE),intsize,i,j,filetype,cart_comm
integer::fh
integer(kind=mpi_offset_kind):: offset=0
integer::buff(2,3)
character:: filename*50
integer::sizes(2)
integer::gsize(2)
integer::start(2)
integer::subsize(2)
integer::coords(2)
integer:: nprocs_cart(2)=(/2,3/)
logical::periods(2)
intsize=sizeof(rank)
call MPI_init(ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
CALL MPI_Dims_create(nproc, 2, nprocs_cart, ierr)
CALL MPI_Cart_create(MPI_COMM_WORLD, 2, nprocs_cart, periods, .TRUE., &
cart_comm, ierr)
CALL MPI_Comm_rank(cart_comm, rank, ierr)
CALL MPI_Cart_coords(cart_comm, rank, 2, coords, ierr)
start=coords
gsize=(/2,3/)
subsize=(/1,1/)
buff=1
call MPI_TYPE_CREATE_SUBARRAY(2,gsize,subsize,start,MPI_ORDER_FORTRAN,&
MPI_int,filetype,ierr)
call MPI_TYPE_COMMIT(filetype,ierr)
call MPI_File_open(MPI_COMM_WORLD,'out.dat',&
MPI_MODE_WRONLY + MPI_MODE_CREATE, MPI_INFO_NULL, fh,ierr)
call MPI_File_set_view(fh,0,MPI_int,filetype,&
"native",MPI_INFO_NULL,ierr)
CALL MPI_FILE_WRITE_all(fh, buff,6, filetype, MPI_STATUS_ignore, ierr)
call MPI_File_close(fh,ierr)
call MPI_FINALIZE(ierr)
end program test