HP-MPI User's Guide (11th Edition)
Example applications
multi_par.f
Appendix A 255
c indices specify a portion (the j'th portion) of a row, and
the
c datatype cdtype(j) is created as an MPI vector datatype to
refer
c to the j'th portion of a row. Note this a vector datatype
c because adjacent elements in a row are actually spaced nrow
c elements apart in memory.
c
allocate(rbs(0:comm_size-1),rbe(0:comm_size-1),cbs(0:comm_size-1)
,
* cbe(0:comm_size-1),rdtype(0:comm_size-1),
* cdtype(0:comm_size-1),twdtype(0:comm_size-1))
do blk=0,comm_size-1
call blockasgn(1,nrow,comm_size,blk,rbs(blk),rbe(blk))
call mpi_type_contiguous(rbe(blk)-rbs(blk)+1,
* mpi_double_precision,rdtype(blk),ierr)
call mpi_type_commit(rdtype(blk),ierr)
call blockasgn(1,ncol,comm_size,blk,cbs(blk),cbe(blk))
call mpi_type_vector(cbe(blk)-cbs(blk)+1,1,nrow,
* mpi_double_precision,cdtype(blk),ierr)
call mpi_type_commit(cdtype(blk),ierr)
enddo
c Compose MPI datatypes for gather/scatter
c
c Each block of the partitioning is defined as a set of fixed
length
c vectors. Each process'es partition is defined as a struct
of such
c blocks.
c
allocate(adtype(0:comm_size-1),adisp(0:comm_size-1),
* ablen(0:comm_size-1))
call mpi_type_extent(mpi_double_precision,dsize,ierr)
do rank=0,comm_size-1
do rb=0,comm_size-1
cb=mod(rb+rank,comm_size)
call
mpi_type_vector(cbe(cb)-cbs(cb)+1,rbe(rb)-rbs(rb)+1,
* nrow,mpi_double_precision,adtype(rb),ierr)
call mpi_type_commit(adtype(rb),ierr)
adisp(rb)=((rbs(rb)-1)+(cbs(cb)-1)*nrow)*dsize
ablen(rb)=1
enddo
call mpi_type_struct(comm_size,ablen,adisp,adtype,
* twdtype(rank),ierr)
call mpi_type_commit(twdtype(rank),ierr)
do rb=0,comm_size-1
call mpi_type_free(adtype(rb),ierr)
enddo
enddo
deallocate(adtype,adisp,ablen)