! roll_call.F check that processors are available program roll_call include 'mpif.h' ! use my_mpif.h not available on your system implicit none integer :: proc, numprocs integer :: myid ! myid is 0 to numprocs-1 integer :: count = 1 integer :: tag = 0 integer :: master = 0 double precision :: esec integer, dimension(1000) :: buf ! subscripts start at 1 integer :: status integer :: ierr ! "C" return as last argument call MPI_Init(ierr) call MPI_Comm_size(MPI_COMM_WORLD, numprocs, ierr) call MPI_Comm_rank(MPI_COMM_WORLD, myid, ierr) if(myid == master) then print *, 'roll_call.F numprocs=', numprocs print *, 'printout may not be in order on multiprocessors' do proc=0,numprocs-1 ! rank starts at zero, last is numprocs-1 buf(1) = 10*proc call MPI_Send(buf, count, MPI_INTEGER, proc, tag, MPI_COMM_WORLD, & ierr) buf(1) = 1 call MPI_Recv(buf, count, MPI_INTEGER, proc, tag, MPI_COMM_WORLD, & status, ierr) print *, 'proc', proc, ' answers with ', buf(1) end do esec = MPI_Wtime() print *, 'roll_call.c took', esec, ' seconds' else ! slaves call MPI_Recv(buf, count, MPI_INTEGER, master, tag, MPI_COMM_WORLD, & status, ierr) print *, 'proc', myid, ' received', buf(1) buf(1) = 10*buf(1) call MPI_Send(buf, count, MPI_INTEGER, master, tag, MPI_COMM_WORLD, & ierr) end if call MPI_Finalize(ierr) end ! roll_call.F