HP-MPI User's Guide (11th Edition)
Example applications
master_worker.f90
Appendix A244
call MPI_Recv(result(index), chunksize, MPI_REAL, source,
1, &
MPI_COMM_WORLD, status, ierr)
end do
do i = 1, numworkers*chunksize
if (result(i) .ne. (i+1)) then
print *, 'element ', i, ' expecting ', (i+1), ' actual
is ', result(i)
numfail = numfail + 1
endif
enddo
if (numfail .ne. 0) then
print *, 'out of ', ARRAYSIZE, ' elements, ', numfail, '
wrong answers'
else
print *, 'correct results!'
endif
end if
! ******************************* Worker task
*******************************
if (taskid .gt. MASTER) then
call MPI_Recv(index, 1, MPI_INTEGER, MASTER, 0,
MPI_COMM_WORLD, &
status, ierr)
call MPI_Recv(result(index), chunksize, MPI_REAL, MASTER, 0,
&
MPI_COMM_WORLD, status, ierr)
do i = index, index + chunksize - 1
result(i) = i + 1
end do
call MPI_Send(index, 1, MPI_INTEGER, MASTER, 1,
MPI_COMM_WORLD, ierr)
call MPI_Send(result(index), chunksize, MPI_REAL, MASTER, 1,
&
MPI_COMM_WORLD, ierr)
end if
call MPI_Finalize(ierr)
end program array_manipulation
master_worker output
The output from running the master_worker executable is shown below.
The application was run with -np = 2.
correct results!