// mpi example for matrix vector product // // compute the matrix-vector production // by cutting the matrix along rows // #include "mpi.h" #include #include #include #define N 1024 int main(int argc, char *argv[]) { int myid, np, err, NL, Nk, Nr; 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); int rc[np], disp[np]; Nk = N / np; Nr = N % np; if (myid < Nr) NL = Nk + 1; else NL = Nk; 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, 1); } t = MPI_Wtime(); // time // set initial value for(j=0; j