5 #define MAX_PROCESSES 10
7 int main( int argc, char **argv )
10 int table[MAX_PROCESSES][MAX_PROCESSES];
11 int row[MAX_PROCESSES];
14 int displs[MAX_PROCESSES];
15 int send_counts[MAX_PROCESSES];
17 MPI_Init( &argc, &argv );
18 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
19 MPI_Comm_size( MPI_COMM_WORLD, &size );
21 /* A maximum of MAX_PROCESSES processes can participate */
22 if ( size > MAX_PROCESSES ) participants = MAX_PROCESSES;
23 else participants = size;
24 if ( (rank < participants) ) {
25 int recv_count = MAX_PROCESSES;
27 /* If I'm the root (process 0), then fill out the big table */
28 /* and setup send_counts and displs arrays */
30 for ( i=0; i<participants; i++) {
31 send_counts[i] = recv_count;
32 displs[i] = i * MAX_PROCESSES;
33 for ( j=0; j<MAX_PROCESSES; j++ )
37 /* Scatter the big table to everybody's little table */
38 MPI_Scatterv(&table[0][0], send_counts, displs, MPI_INT,
39 &row[0] , recv_count, MPI_INT, 0, MPI_COMM_WORLD);
41 /* Now see if our row looks right */
42 for (i=0; i<MAX_PROCESSES; i++)
43 if ( row[i] != i+rank ) errors++;
49 printf( "[%d] done with ERRORS(%d)!\n", rank, errors );