#include <stdio.h> #include "mpi.h" #define maxn 5 int main(int argc, char **argv ) { int rank, size, i, j; MPI_Status status; double x[maxn][maxn]; double recvbuf[maxn]; int row,col; MPI_Datatype Col; MPI_Init( &argc, &argv ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); if (maxn % (size-1) != 0 ) { if (rank==0) printf("Sorry, np-1 must divide into %d\n", maxn); MPI_Abort( MPI_COMM_WORLD, 1 ); } if (rank == 0) { /* Fill the data as specified */ for (i=0; i <maxn; i++) for (j=0; j<maxn; j++) x[i][j] = rand() % 10; printf("Matrix X:\n"); for (i=0; i<maxn; i++) { for (j=0; j<maxn; j++) printf("%4.1f", x[i][j]); printf("\n"); } } count = maxn/(size-1); if (rank==0) { //SEND EACH ROW OF MATRIX X TO A SEPARATE PROCESS //PRINT EACH ROW FROM EACH PROCESS //MPI_Send(&x[0],1, MPI_DOUBLE,1 , 0, MPI_COMM_WORLD); //The above sends row 1 (0th row) to process 1 //Use a loop to send to each process } } if (rank>0) { printf("Process: %d, RECVBUF:\n", rank); //PRINT OUT EACH ROW FROM A DIFFERENT PROCESS // printf("%4.1f", recvbuf[ ]); } */ MPI_Finalize( ); return 0; }