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