#include "mpi.h" #include #include #include // mpicc -o sc scattermatrix.c && /usr/lib/mpich-mpd/bin/mpirun -np 4 ./sc #define MAXN 10 void print_row(char* name, int* R,int i, int N, int rank) { int j; printf("@[%d] (%s): ", rank, name); for(j=0; j \n", rank); for(i=0; i\n", i); if (i < (N - last)) { MPI_Scatter( &newtable[i * N + 0], 1, subarray, &newtable[(i + rank) * N + 0], 1, subarray, 0,MPI_COMM_WORLD); } else { if (rank < last) { MPI_Scatter( &newtable[i * N + 0], 1, subarray, &newtable[ (i + rank) * N + 0], 1, subarray, 0, COMM_LAST); } } } MPI_Barrier(MPI_COMM_WORLD); for(r = 0; r < size; r++) { MPI_Barrier(MPI_COMM_WORLD); if(rank == r) { printf("@[%d] -> \n", rank); for(i=0; i\n", i); if (i < (N - last)) { MPI_Gather( &newtable[ ( i + rank ) * N + 0], 1, subarray, &newtable[i * N + 0], 1, subarray, 0, MPI_COMM_WORLD); } else { if (rank < last) { MPI_Gather( &newtable[(i + rank) * N + 0], 1, subarray, &newtable[i*N + 0], 1, subarray, 0,COMM_LAST); } } } if (rank == 0) { for(r = 0; r < size; r++) { printf("@[%d]\n", rank); if(rank == r) { for(i=0; i