// mpi example for matrix vector product // // compute the matrix-vector production // by cutting the matrix along rows // #include "mpi.h" #include #include #include #define P 4 #define N 1024 #define NL N/P int main(int argc, char *argv[]) { int myid, np, root; int i, j, lr; double t, (*pA)[N], *px, *pyl, *py; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &np); if ( np != P & myid == 0) { printf("Error: P not equal to np!\n"); MPI_Abort(MPI_COMM_WORLD, 1); } pA = malloc(NL*N*sizeof(double)); px = malloc(N*sizeof(double)); pyl = malloc(NL*sizeof(double)); py = malloc(N*sizeof(double)); if (!pA | !px | !pyl | !py) { printf("Out of memory!\n"); MPI_Abort(MPI_COMM_WORLD, 2); } t = MPI_Wtime(); // time // set initial value for(j=0; j