参考自:https://blog.csdn.net/lcx543576178/article/details/45892839
程序稍作修改,如下:
#include
using namespacestd;
#include
int main(int argc, char *argv[] ){doublestart, stop;int *a, *b, *c, *buffer, *ans;int size = 1000;intrank, numprocs, line;
MPI_Init(NULL,NULL);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
line= size/numprocs;
b= new int [ size *size ];
ans= new int [ size *line ];
start=MPI_Wtime();if( rank ==0){
a= new int [ size *size ];
c= new int [ size *size ];for(int i=0;i
a[ i*size + j ] = i*j;
b[ i*size + j ] = i +j;
}for(int i=1;i
MPI_Send( b, size*size, MPI_INT, i, 0, MPI_COMM_WORLD );
}for(int i=1;i
MPI_Send( a + (i-1)*line*size,