HP-MPI User's Guide (11th Edition)
Example applications
multi_par.f
Appendix A256
c Scatter initial data with using derived datatypes defined
above
c for the partitioning. MPI_send() and MPI_recv() will find
out the
c layout of the data from those datatypes. This saves
application
c programs to manually pack/unpack the data, and more
importantly,
c gives opportunities to the MPI system for optimal
communication
c strategies.
c
if (comm_rank.eq.0) then
do dest=1,comm_size-1
call
mpi_send(array,1,twdtype(dest),dest,0,mpi_comm_world,
* ierr)
enddo
else
call
mpi_recv(array,1,twdtype(comm_rank),0,0,mpi_comm_world,
* mstat,ierr)
endif
c
c Computation
c
c Sum up in each column.
c Each MPI process, or a rank, computes blocks that it is
assigned.
c The column block number is assigned in the variable 'cb'.
The
c starting and ending subscripts of the column block 'cb' are
c stored in 'cbs(cb)' and 'cbe(cb)', respectively. The row
block
c number is assigned in the variable 'rb'. The starting and
ending
c subscripts of the row block 'rb' are stored in 'rbs(rb)'
and
c 'rbe(rb)', respectively, as well.
src=mod(comm_rank+1,comm_size)
dest=mod(comm_rank-1+comm_size,comm_size)
ncb=comm_rank
do rb=0,comm_size-1
cb=ncb
c
c Compute a block. The function will go thread-parallel if
the
c compiler supports OPENMP directives.
c
call compcolumn(nrow,ncol,array,
* rbs(rb),rbe(rb),cbs(cb),cbe(cb))
if (rb.lt.comm_size-1) then
c
c Send the last row of the block to the rank that is to
compute the