Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / coll / coll2.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include "test.h"
4
5 #define MAX_PROCESSES 10
6
7 int main( int argc, char **argv )
8 {
9     int              rank, size, i,j;
10     int              table[MAX_PROCESSES][MAX_PROCESSES];
11     int              errors=0;
12     int              participants;
13     MPI_Comm         testcomm;
14
15     MPI_Init( &argc, &argv );
16     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
17     MPI_Comm_size( MPI_COMM_WORLD, &size );
18
19     /* A maximum of MAX_PROCESSES processes can participate */
20     if ( size > MAX_PROCESSES ) participants = MAX_PROCESSES;
21     else              participants = size;
22     /* Set the particpants so that it divides the MAX_PROCESSES */
23     while (MAX_PROCESSES % participants) participants--;
24     /* Create the communicator */
25     MPI_Comm_split( MPI_COMM_WORLD, rank < participants, rank, &testcomm );
26
27     if (MAX_PROCESSES % participants) {
28         fprintf( stderr, "Number of processors must divide %d\n",
29                 MAX_PROCESSES );
30         MPI_Abort( MPI_COMM_WORLD, 1 );
31         }
32     if ( (rank < participants) ) {
33
34       /* Determine what rows are my responsibility */
35       int block_size = MAX_PROCESSES / participants;
36       int begin_row  = rank * block_size;
37       int end_row    = (rank+1) * block_size;
38       int send_count = block_size * MAX_PROCESSES;
39       int recv_count = send_count;
40
41       /* Paint my rows my color */
42       for (i=begin_row; i<end_row ;i++)
43         for (j=0; j<MAX_PROCESSES; j++)
44           table[i][j] = rank + 10;
45
46       /* Gather everybody's result together - sort of like an */
47       /* inefficient allgather */
48       for (i=0; i<participants; i++)
49         MPI_Gather(&table[begin_row][0], send_count, MPI_INT, 
50                    &table[0][0],         recv_count, MPI_INT, i, 
51                    testcomm );
52
53       /* Everybody should have the same table now,  */
54       /* This test does not in any way guarantee there are no errors */
55       /* Print out a table or devise a smart test to make sure it's correct */
56       for (i=0; i<MAX_PROCESSES;i++) {
57         if ( (table[i][0] - table[i][MAX_PROCESSES-1] !=0) ) 
58           errors++;
59       }
60     } 
61
62     MPI_Comm_free( &testcomm );
63     Test_Waitforall( );
64     MPI_Finalize();
65     if (errors)
66       printf( "[%d] done with ERRORS(%d)!\n", rank, errors );
67     return errors;
68 }