PROGRAM mpi2io USE MPI IMPLICIT none INTEGER :: myrank, nproc,ierr; INTEGER, PARAMETER :: dim_buf = 10 INTEGER :: buf(dim_buf) INTEGER :: i, intsize; INTEGER(KIND=MPI_OFFSET_KIND) :: offset, file_size INTEGER :: fh INTEGER :: status(MPI_STATUS_SIZE) INTEGER :: filetype CALL MPI_Init(ierr); CALL MPI_Comm_size(MPI_COMM_WORLD,nproc,ierr) CALL MPI_Comm_rank(MPI_COMM_WORLD,myrank,ierr) DO i=1,dim_buf buf(i) = myrank*dim_buf+i-1; END DO ! Open the file and write CALL MPI_File_open(MPI_COMM_WORLD, "output.dat", MPI_MODE_CREATE+MPI_MODE_WRONLY, MPI_INFO_NULL,fh,ierr) CALL MPI_File_write_ordered(fh, buf, dim_buf, MPI_INTEGER, status, ierr) ! a write with individual file pointers could also be used: ! CALL MPI_Type_size(MPI_INTEGER,intsize,ierr) ! offset = myrank*dim_buf*(intsize) ! CALL MPI_File_seek(fh,offset,MPI_SEEK_SET,ierr) ! CALL MPI_File_write(fh,buf,dim_buf,MPI_INTEGER,status,ierr) CALL MPI_File_close(fh,ierr) ! Re-open the file and read data CALL MPI_File_open(MPI_COMM_WORLD,"output.dat",MPI_MODE_RDONLY,MPI_INFO_NULL,fh,ierr) CALL MPI_File_read_ordered(fh, buf, dim_buf, MPI_INTEGER, status, ierr) ! a read with individual file pointers could also be used: ! CALL MPI_File_get_size(fh,file_size,ierr) ! offset = file_size/nproc*myrank ! write(6,*) "myid ",myrank,"filesize ", file_size, "offset ", offset ! CALL MPI_File_read_at(fh,offset,buf,dim_buf,MPI_INTEGER,status,ierr) CALL MPI_File_close(fh,ierr) WRITE(*,*) "myid ",myrank," buffer after read:" WRITE(*,*) buf CALL MPI_File_close(fh,ierr) CALL MPI_Finalize(ierr) END PROGRAM mpi2io