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];
18 int displs[MAX_PROCESSES];
19 int recv_counts[MAX_PROCESSES];
22 MTest_Init( &argc, &argv );
23 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
24 MPI_Comm_size( MPI_COMM_WORLD, &size );
26 /* A maximum of MAX_PROCESSES processes can participate */
27 participants = ( size > MAX_PROCESSES ) ? MAX_PROCESSES : size;
29 if (MAX_PROCESSES % participants) {
30 fprintf( stderr, "Number of processors must divide %d\n",
32 MPI_Abort( MPI_COMM_WORLD, 1 );
34 MPI_Comm_split(MPI_COMM_WORLD, rank<participants, rank, &test_comm);
36 if ( rank < participants ) {
38 /* Determine what rows are my responsibility */
39 int block_size = MAX_PROCESSES / participants;
40 int begin_row = rank * block_size;
41 int end_row = (rank+1) * block_size;
42 int send_count = block_size * MAX_PROCESSES;
44 /* Fill in the displacements and recv_counts */
45 for (i=0; i<participants; i++) {
46 displs[i] = i * block_size * MAX_PROCESSES;
47 recv_counts[i] = send_count;
50 /* Paint my rows my color */
51 for (i=begin_row; i<end_row ;i++)
52 for (j=0; j<MAX_PROCESSES; j++)
53 table[i][j] = rank + 10;
55 /* Everybody gets the gathered data */
56 MPI_Allgatherv(&table[begin_row][0], send_count, MPI_INT,
57 &table[0][0], recv_counts, displs,
60 /* Everybody should have the same table now.
63 Table[i][j] = (i/block_size) + 10;
65 for (i=0; i<MAX_PROCESSES;i++)
66 if ( (table[i][0] - table[i][MAX_PROCESSES-1] !=0) )
68 for (i=0; i<MAX_PROCESSES;i++) {
69 for (j=0; j<MAX_PROCESSES;j++) {
70 if (table[i][j] != (i/block_size) + 10) errors++;
74 /* Print out table if there are any errors */
75 for (i=0; i<MAX_PROCESSES;i++) {
77 for (j=0; j<MAX_PROCESSES; j++)
78 printf(" %d",table[i][j]);
84 MTest_Finalize( errors );
86 MPI_Comm_free(&test_comm);
88 return MTestReturnValue( errors );