wiki:cypress/Programming/FortranExamples/MpiFortran

MPI FORTRAN

Hello World

!hello_mpi.f90: display a message on the screen 
program helloworld
  include'mpif.h'
  !
  integer::myid, numproc, ierr
  ! Initialize  
  CALL MPI_INIT( ierr )  
  !
  ! get myid and # of processors 
  CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
  CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numproc, ierr )
 
  print *,"hello from ", myid
 
  ! wait until all processors come here 
  CALL MPI_Barrier (MPI_COMM_WORLD,ierr);
 
  if (myid == 0) then
     ! only myid = 0 do this 
     print *, numproc," processors said hello!"
  endif
 
  CALL  MPI_Finalize(ierr);
end program helloworld

Compile

mpif90 hello_mpi.f90

Example of Jobscript

See Example

Last modified 5 years ago Last modified on May 15, 2015 10:03:30 AM