I am learning MPI-IO and following a tutorial (PDF download here).
For one exercise, the correct code is:
Program MPI_IOTEST
Use MPI
Implicit None
Integer :: wsize,wrank
Integer :: ierror
Integer :: fh,offset
Call MPI_Init(ierror)
Call MPI_Comm_rank(MPI_COMM_WORLD,wrank,ierror)
Call MPI_Comm_size(MPI_COMM_WORLD,wsize,ierror)
offset=4*wrank; ! because 4 bytes is one signed int
! --- open the MPI files using a collective call
Call MPI_File_Open(MPI_COMM_WORLD,'test.dat',MPI_MODE_RDWR+MPI_MODE_CREATE,MPI_INFO_NULL,fh,ierror);
Write(*,*)'rank',wrank
Call MPI_FILE_WRITE_AT(fh, offset, wrank,1,MPI_INTEGER,mpi_status_ignore,ierror);
Call MPI_File_close(fh,ierror)
Call MPI_Finalize(ierror)
End Program MPI_IOTEST
Then you just build and run it as 24 MPI tasks. Then for validation, simply do od -i test/dat You will get the result exactly the same on the tutorial, which is given below.
0000000 0 1 2 3
0000020 4 5 6 7
0000040 8 9 10 11
0000060 12 13 14 15
0000100 16 17 18 19
0000120 20 21 22 23
0000140
But if I change 1 to num:
Call MPI_FILE_WRITE_AT(fh, offset, wrank,1,MPI_INTEGER,mpi_status_ignore,ierror);
into
Call MPI_FILE_WRITE_AT(fh, offset, wrank,num,MPI_INTEGER,mpi_status_ignore,ierror);
and before that define
integer :: num
num=1
After rm test.dat, then re-build the file and run it, you will get:
0000000 0 0 0 0
*