| 41 | } |
| 42 | |
| 43 | void Matrix_cannon_scatter(int N,int id,int num,int part,float *source_matrix,float *target_matrix,MPI_Comm MPI_COMM_CART){ |
| 44 | float *matrixpool;//用于分发矩阵的一维向量 |
| 45 | int i,j,w,h,count=0; |
| 46 | if(id==0){//(0,0)进程 |
| 47 | matrixpool=(float *)malloc(sizeof(float)*N*N); |
| 48 | //将矩阵source_matrix重新排序放入matrixpool |
| 49 | for(w=0;w<part;w++) |
| 50 | for(h=0;h<part;h++) |
| 51 | for(i=w*num;i<(w+1)*num;i++) |
| 52 | for(j=h*num;j<(h+1)*num;j++) |
| 53 | matrixpool[count++] = source_matrix[i*N+j]; |
| 54 | } |
| 55 | MPI_Scatter(matrixpool,num*num,MPI_FLOAT,target_matrix,num*num,MPI_FLOAT,0,MPI_COMM_CART); |
| 56 | if(id==0){ |
| 57 | free(matrixpool); |
| 58 | } |
| 59 | } |
| 60 | void Matrix_cannon_gather(int N,int id,int num,int part,float *source_c,float *target_c,MPI_Comm MPI_COMM_CART){ |
| 61 | float *matrixpool;//用于收集C矩阵的一维向量 |
| 62 | int i,j,w,h,posi; |