1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 #define MAX_PROCESSES 10
12 int main( int argc, char **argv )
15 int table[MAX_PROCESSES][MAX_PROCESSES];
19 MTest_Init( &argc, &argv );
20 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
21 MPI_Comm_size( MPI_COMM_WORLD, &size );
23 /* A maximum of MAX_PROCESSES processes can participate */
24 if ( size > MAX_PROCESSES ) participants = MAX_PROCESSES;
25 else participants = size;
26 if (MAX_PROCESSES % participants) {
27 fprintf( stderr, "Number of processors must divide %d\n",
29 MPI_Abort( MPI_COMM_WORLD, 1 );
32 /* while (MAX_PROCESSES % participants) participants--; */
33 if ( (rank < participants) ) {
35 /* Determine what rows are my responsibility */
36 int block_size = MAX_PROCESSES / participants;
37 int begin_row = rank * block_size;
38 int end_row = (rank+1) * block_size;
39 int send_count = block_size * MAX_PROCESSES;
40 int recv_count = send_count;
42 /* Paint my rows my color */
43 for (i=begin_row; i<end_row ;i++)
44 for (j=0; j<MAX_PROCESSES; j++)
45 table[i][j] = rank + 10;
47 /* Everybody gets the gathered table */
48 MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL,
49 &table[0][0], recv_count, MPI_INT, MPI_COMM_WORLD);
51 /* Everybody should have the same table now, */
52 /* This test does not in any way guarantee there are no errors */
53 /* Print out a table or devise a smart test to make sure it's correct */
54 for (i=0; i<MAX_PROCESSES;i++) {
55 if ( (table[i][0] - table[i][MAX_PROCESSES-1] !=0) )
60 MTest_Finalize( errors );
62 return MTestReturnValue( errors );