5 #define MAX_PROCESSES 10
7 int main( int argc, char **argv )
10 int table[MAX_PROCESSES][MAX_PROCESSES];
14 MPI_Init( &argc, &argv );
15 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
16 MPI_Comm_size( MPI_COMM_WORLD, &size );
18 /* A maximum of MAX_PROCESSES processes can participate */
19 if ( size > MAX_PROCESSES ) participants = MAX_PROCESSES;
20 else participants = size;
21 if (MAX_PROCESSES % participants) {
22 fprintf( stderr, "Number of processors must divide %d\n",
24 MPI_Abort( MPI_COMM_WORLD, 1 );
26 /* while (MAX_PROCESSES % participants) participants--; */
27 if ( (rank < participants) ) {
29 /* Determine what rows are my responsibility */
30 int block_size = MAX_PROCESSES / participants;
31 int begin_row = rank * block_size;
32 int end_row = (rank+1) * block_size;
33 int send_count = block_size * MAX_PROCESSES;
34 int recv_count = send_count;
36 /* Paint my rows my color */
37 for (i=begin_row; i<end_row ;i++)
38 for (j=0; j<MAX_PROCESSES; j++)
39 table[i][j] = rank + 10;
41 /* Everybody gets the gathered table */
42 MPI_Allgather(&table[begin_row][0], send_count, MPI_INT,
43 &table[0][0], recv_count, MPI_INT, MPI_COMM_WORLD);
45 /* Everybody should have the same table now, */
46 /* This test does not in any way guarantee there are no errors */
47 /* Print out a table or devise a smart test to make sure it's correct */
48 for (i=0; i<MAX_PROCESSES;i++) {
49 if ( (table[i][0] - table[i][MAX_PROCESSES-1] !=0) )
57 printf( "[%d] done with ERRORS(%d)!\n", rank, errors );