m0n0lithic

fortran-77 (fixed format): mpi.f

May 20th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! example of parallel MPI write into a single file, in Fortran
  2.       PROGRAM main
  3. ! Fortran 90 users can (and should) use
  4. ! use mpi
  5. ! instead of include 'mpif.h' if their MPI implementation provides a
  6. ! mpi module.
  7.       include 'mpif.h'
  8.  
  9.       integer ierr, i, myrank, BUFSIZE, thefile
  10.       parameter (BUFSIZE=100)
  11.       integer buf(BUFSIZE)
  12.       integer(kind=MPI_OFFSET_KIND) disp
  13.  
  14.       call MPI_INIT(ierr)
  15.       call MPI_COMM_RANK(MPI_COMM_WORLD, myrank, ierr)
  16.  
  17.       do i = 0, BUFSIZE
  18.       buf(i) = myrank * BUFSIZE + i
  19.       enddo
  20.       call MPI_FILE_OPEN(MPI_COMM_WORLD,
  21.      \'pvfs2:/mnt/pvfs2/mpio/testfile02', MPI_MODE_WRONLY +
  22.      MPI_MODE_CREATE, MPI_INFO_NULL, thefile, ierr)
  23. ! assume 4-byte integers
  24.       disp = myrank * BUFSIZE * 4
  25.       call MPI_FILE_SET_VIEW(thefile, disp, MPI_INTEGER, MPI_INTEGER,
  26.      \'native', MPI_INFO_NULL, ierr)
  27.       call MPI_FILE_WRITE(thefile, buf, BUFSIZE, MPI_INTEGER,
  28.      MPI_STATUS_IGNORE, ierr)
  29.       call MPI_FILE_CLOSE(thefile, ierr)
  30.       call MPI_FINALIZE(ierr)
  31.  
  32.       END PROGRAM main
Advertisement
Add Comment
Please, Sign In to add comment