Program example2 c################################################################################## c# # c# This is the second MPI example to demonstrate the use of: # c# # c# * MPI_Init, MPI_Comm_rank, MPI_Comm_size, MPI_Finalize # c# # c# Dr. Kadin Tseng # c# Scientific Computing and Visualization # c# Boston University # c# 1998 # c# # c################################################################################## implicit none integer nprocs, ierr, myid, comm, master, tag, proc character*21 sendbuf, recvbuf include 'mpif.h' ! brings in pre-defined MPI constants, ... integer status(MPI_STATUS_SIZE) ! size defined in mpif.h data master/0/, tag/123/ comm = MPI_COMM_WORLD call MPI_Init(ierr) ! starts MPI call MPI_Comm_rank(comm, myid, ierr) ! get current proc ID call MPI_Comm_size(comm, nprocs, ierr) ! get number of procs if (myid .eq. master) then sendbuf = 'Hello, I am process 0' do proc=1,nprocs-1 call MPI_Send( & sendbuf, 21, MPI_CHARACTER, ! buffer, size, datatype & proc, ! where to send message & tag, ! message tag & comm, ierr) enddo else call MPI_Recv( & recvbuf, 21, MPI_CHARACTER, ! receive buffer, size, datatype & master, ! message receive from & tag, ! message tag & comm, status, ierr) ! status reports source, tag write(*,"('I am process ',i2,'; I receive from ', & i2,' the message: ',a21)")myid,master,recvbuf endif call MPI_Finalize(ierr) ! MPI finish up ... end