/* mpi example for matrix matrix product -- row-column partition -- dim(A) is an integral multiple of np */ #include "mpi.h" #include #include #include #define NP 4 #define N 1024 #define NL N/NP int main(int argc, char *argv[]) { int myid, np; int i, j, k, ii, ij, ik, shift, src, dest; double t, (*pA)[N], (*pB)[NL], (*pC)[N]; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &np); if ( (np != NP) && (myid == 0) ) { printf("Error: np not equal NP\n"); MPI_Abort(MPI_COMM_WORLD, 1); } pA = malloc(NL*N*sizeof(double)); pB = malloc(N*NL*sizeof(double)); pC = malloc(NL*N*sizeof(double)); if ( !pA | !pB | !pC ) { printf("Out of memory!\n"); MPI_Abort(MPI_COMM_WORLD, 2); } t = MPI_Wtime(); // time // set initial value shift = myid*NL; for(i=0; i