* * * * * * * * * * * 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
您可能关注的文档
最近下载
- 施工现场各类设备机械安全监理实施细则(参考).doc VIP
- 华东交通大学2015-2016第一学期电牵专业《电机与拖动》期末A卷.doc VIP
- 储气罐专业定期检查表.docx VIP
- JB_T 14788-2024《连续延伸带式输送机》.pdf VIP
- GB 265-1988 运动黏度.pdf
- 山东省青岛市胶州市2024-2025学年七年级上学期期末历史试题(含答案).pdf VIP
- 基于概念整合理论研究母语对二语写作的影响-外国语言学及应用语言学专业论文.docx VIP
- 中国旅游地理第四章旅游区划.ppt VIP
- 《陆上风力发电机组钢混塔架施工关键材料技术规程》.pdf VIP
- 2025年AI图像识别服务合同协议合同.docx VIP
原创力文档

文档评论(0)