5 #define MAX_PROCESSES 10
7 int main( int argc, char **argv )
10 int table[MAX_PROCESSES][MAX_PROCESSES];
11 int row[MAX_PROCESSES];
15 MPI_Init( &argc, &argv );
16 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
17 MPI_Comm_size( MPI_COMM_WORLD, &size );
19 /* A maximum of MAX_PROCESSES processes can participate */
20 if ( size > MAX_PROCESSES ) participants = MAX_PROCESSES;
21 else participants = size;
22 if ( (rank < participants) ) {
23 int send_count = MAX_PROCESSES;
24 int recv_count = MAX_PROCESSES;
26 /* If I'm the root (process 0), then fill out the big table */
28 for ( i=0; i<participants; i++)
29 for ( j=0; j<MAX_PROCESSES; j++ )
32 /* Scatter the big table to everybody's little table */
33 MPI_Scatter(&table[0][0], send_count, MPI_INT,
34 &row[0] , recv_count, MPI_INT, 0, MPI_COMM_WORLD);
36 /* Now see if our row looks right */
37 for (i=0; i<MAX_PROCESSES; i++)
38 if ( row[i] != i+rank ) errors++;
44 printf( "[%d] done with ERRORS(%d)!\n", rank, errors );