文档详情

《MPI并行编程原理及程序设计》.ppt

发布:2015-10-29约5.01万字共219页下载文档
文本预览下载声明
* * * * * * * * * * * MPI并行程序设计 */217 #include mpi.h #define arysize 256 #define arysize2 (arysize/2) int main(int argc, char *argv[]) { int n, myid, numprocs, i, j, nsteps=10; float a[arysize2+1][arysize2+1],b[arysize2+1][arysize2+1]; double starttime,endtime; /* float send_buf[arysize2],recv_buf[arysize2] ;*/ int col_tag,row_tag,send_col,send_row,recv_col,recv_row; int col_neighbor,row_neighbor; MPI_Comm comm2d; MPI_Datatype newtype; int zero=0,one=1; int right,left,down,top,top_bound,left_bound; * MPI并行程序设计 */217 int periods[2]; int dims[2],begin_row,end_row; MPI_Status status; MPI_Init(argc,argv); dims[0] = 2; dims[1] = 2; periods[0]=0; periods[1]=0; MPI_Cart_create( MPI_COMM_WORLD, 2, dims, periods, 0,comm2d); MPI_Comm_rank(comm2d,myid); MPI_Type_vector( arysize2, 1, arysize2+1,MPI_FLOAT,newtype); MPI_Type_commit( newtype ); MPI_Cart_shift( comm2d, 0, 1, left, right); MPI_Cart_shift( comm2d, 1, 1, down, top); * MPI并行程序设计 */217 for(i=0;iarysize2+1;i++) for(j=0;jarysize2+1;j++) a[i][j]=0.0; if (top == MPI_PROC_NULL) { for ( i=0;iarysize2+1;i++) a[0][i]=8.0; } if (down == MPI_PROC_NULL) { for ( i=0;iarysize2+1;i++) a[arysize2][i]=8.0; } * MPI并行程序设计 */217 if (left == MPI_PROC_NULL) { for ( i=0;iarysize2+1;i++) a[i][0]=8.0; } if (right == MPI_PROC_NULL) { for ( i=0;iarysize2+1;i++) a[i][arysize2]=8.0; } col_tag = 5; row_tag = 6; printf(Laplace Jacobi#C(BLOCK,BLOCK)#myid=%d#step=%d#total arysize=%d*%d\n,myid,nsteps,arysize,arysize); * MPI并行程序设计 */217 top_bound=1; left_bound=1; if (top == MPI_PROC_NULL) top_bound=0; if (left == MPI_PROC_NULL) left_bound=0; starttime=MPI_Wtime(); for (n=0; nnsteps; n++) { MPI_Sendrecv( a[1][left_bound], arysize2, MPI_FLOAT, top, row_tag, a[arysize2][left_bound], arysize2, MPI_FLOAT, down, row_tag, comm2d, status ); MPI_Sendrecv( a[arysize2-1][left
显示全部
相似文档