#include #include #include "mpi.h" #define MAXPROC 8 /* Max number of procsses */ #define NAMELEN 80 /* Max length of machine name */ #define LENGTH 8 /* Size of matrix is LENGTH * LENGTH */ main(int argc, char* argv[]) { int i, j, np, me, count; const int nametag = 42; /* Tag value for sending name */ const int datatag = 43; /* Tag value for sending data */ const int root = 0; /* Root process in scatter */ MPI_Status status; /* Status object for receive */ char myname[NAMELEN]; /* Local host name string */ char hostname[MAXPROC][NAMELEN]; /* Received host names */ int x[LENGTH][LENGTH]; /* Send buffer */ int y[LENGTH]; /* Receive buffer */ int *sendcount, *displs; /* Arrays for sendcounts and displacements */ MPI_Init(&argc, &argv); /* Initialize MPI */ MPI_Comm_size(MPI_COMM_WORLD, &np); /* Get nr of processes */ MPI_Comm_rank(MPI_COMM_WORLD, &me); /* Get own identifier */ gethostname(&myname, NAMELEN); /* Get host name */ /* Check that we have one process for each row in the matrix */ if (np != LENGTH) { if (me == 0) { printf("You have to use %d processes\n", LENGTH); } MPI_Finalize(); exit(0); } /* Allocate memory for the sendcount and displacements arrays */ sendcount = (int *)malloc(LENGTH*sizeof(int)); displs = (int *)malloc(LENGTH*sizeof(int)); /* Initialize sendcount and displacements arrays */ for (i=0; i