I have the following code
program mpi_io
use mpi
implicit none
integer :: mpierr, whoami, nproc, iout, STATUS(MPI_STATUS_SIZE),charsize
integer(kind=mpi_offset_kind):: OFFSET, fs
character(len=60) :: dd,de
character:: newline = NEW_LINE('FORTRAN')
call MPI_INIT ( mpierr )
call MPI_COMM_RANK ( MPI_COMM_WORLD, whoami, mpierr )
call MPI_COMM_SIZE ( MPI_COMM_WORLD, nproc, mpierr )
dd ='=========================' // INT2STR(whoami)//newline
de = 'special'// INT2STR(whoami)//newline
call MPI_FILE_OPEN( MPI_COMM_WORLD, 'test.dat', MPI_MODE_CREATE + MPI_MODE_WRONLY, MPI_INFO_NULL, IOUT, mpierr)
call mpi_type_size(mpi_byte, charsize , mpierr)
offset = charsize*len(TRIM(de))
if(whoami == 0)call MPI_FILE_WRITE_AT( iout,offset, TRIM(de), len(TRIM(de)), MPI_BYTE, status, mpierr)
call MPI_File_get_size(iout, fs, mpierr)
offset = fs
call MPI_FILE_SEEK(iout, fs, MPI_SEEK_SET, mpierr)
call MPI_FILE_WRITE_ordered( iout, TRIM(dd), len(TRIM(dd)), MPI_BYTE, status, mpierr)
!call MPI_FILE_WRITE_ordered( iout, dd, len(dd), MPI_CHARACTER, status, mpierr)
call mpi_file_close(iout,mpierr)
call mpi_finalize(mpierr)
contains
function INT2STR( i ) result( str )
integer, intent(in) :: i
character(:), allocatable :: str
character(RANGE(i)+2) :: tmp
write(tmp, '(I0)') i
str = TRIM(tmp)
end function
end program
What I am seeking for is a combination of writing to file by only one processor and sometimes by them all. As you see in this example, I firstly want to write de
by the root rank only, and thereafter dd
by all processors.
Write now, it seems that my de
is being overwritten
As you can see I tried to offset it by querying the size of the file and do a MPI_FILE_SEEK, but it does not seem to help Does anybody have an idea.
I am using IFORT v19