Download Platform MPI User's Guide - Platform Cluster Manager
Transcript
Example Applications partitioning method with OPENMP thread directives. In the first case, the data dependency is easily satisfied because each thread computes down a different set of columns. In the second case we still want to compute down the columns for cache reasons, but to satisfy the data dependency, each thread computes a different portion of the same column and the threads work left to right across the rows together. implicit none include 'mpif.h' integer nrow ! # of rows integer ncol ! # of columns parameter(nrow=1000,ncol=1000) double precision array(nrow,ncol) ! compute region integer blk ! block iteration counter integer rb ! row block number integer cb ! column block number integer nrb ! next row block number integer ncb ! next column block number integer rbs(:) ! row block start subscripts integer rbe(:) ! row block end subscripts integer cbs(:) ! column block start subscripts integer cbe(:) ! column block end subscripts integer rdtype(:) ! row block communication datatypes integer cdtype(:) ! column block communication datatypes integer twdtype(:) ! twisted distribution datatypes integer ablen(:) ! array of block lengths integer adisp(:) ! array of displacements integer adtype(:) ! array of datatypes allocatable rbs,rbe,cbs,cbe,rdtype,cdtype,twdtype,ablen,adisp,adtype integer rank ! rank iteration counter integer comm_size ! number of MPI processes integer comm_rank ! sequential ID of MPI process integer ierr ! MPI error code integer mstat(mpi_status_size) ! MPI function status integer src ! source rank integer dest ! destination rank integer dsize ! size of double precision in bytes double precision startt,endt,elapsed ! time keepers external compcolumn,comprow ! subroutines execute in threads c c c MPI initialization c c c Data initialization and start up c c c c c c c c c c c c c c c c c call mpi_init(ierr) call mpi_comm_size(mpi_comm_world,comm_size,ierr) call mpi_comm_rank(mpi_comm_world,comm_rank,ierr) if (comm_rank.eq.0) then write(6,*) 'Initializing',nrow,' x',ncol,' array...' call getdata(nrow,ncol,array) write(6,*) 'Start computation' endif call mpi_barrier(MPI_COMM_WORLD,ierr) startt=mpi_wtime() Compose MPI datatypes for row/column send-receive Note that the numbers from rbs(i) to rbe(i) are the indices of the rows belonging to the i'th block of rows. These indices specify a portion (the i'th portion) of a column and the datatype rdtype(i) is created as an MPI contiguous datatype to refer to the i'th portion of a column. Note this is a contiguous datatype because fortran arrays are stored column-wise. For a range of columns to specify portions of rows, the situation is similar: the numbers from cbs(j) to cbe(j) are the indices of the columns belonging to the j'th block of columns. These indices specify a portion (the j'th portion) of a row, and the datatype cdtype(j) is created as an MPI vector datatype to refer to the j'th portion of a row. Note this a vector datatype Platform MPI User's Guide 201