#include "stdio.h" #include "mpi.h" /* This brings in pre-defined MPI constants, ... */ void asemble(int at[][], int ml, int nl, MPI_Comm comm, int b[][], int m, int n, int p); void main(int argc, char *argv[]) { int n, m, nv, nl, mv, ml, i, il, iv, j, jl, jv; int p, ndim, reorder, ierr; int master, me, Iam, source, dest, tag; int dims[2], coord[2]; int period[2]; int a[3][2], at[2][3], b[4][9]; MPI_Status status; MPI_Request req; MPI_Comm grid_comm; /* Starts MPI processes ... */ MPI_Init(&argc, &argv); /* starts MPI */ MPI_Comm_rank(MPI_COMM_WORLD, &Iam); /* get current process id */ MPI_Comm_size(MPI_COMM_WORLD, &p); /* get number of processes */ master = 0; /* 0 is defined as the master processor */ period[0] = 0; period[1] = 0; /* no cyclic boundary in either index */ tag = 0; /* a tag is not required in this case, set it to zero */ dest = 0; /* results are sent back to master */ n = 9; m = 4; nv = 3; mv = 2; nl = n/nv; ml = m/mv; ndim = 2; reorder = 1; /* create cartesian topology for matrix */ dims[0] = nv; dims[1] = mv; MPI_Cart_create(MPI_COMM_WORLD, ndim, dims, period, reorder, &grid_comm); MPI_Comm_rank(grid_comm, &me); MPI_Cart_coords(grid_comm, me, ndim, coord); iv = coord[0]; jv = coord[1]; /* define local matrix according to virtual grid coordinates, (iv,jv) */ for (il=0; il