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 / coll6.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     int              displs[MAX_PROCESSES];
14     int              recv_counts[MAX_PROCESSES];
15
16     MPI_Init( &argc, &argv );
17     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
18     MPI_Comm_size( MPI_COMM_WORLD, &size );
19
20     /* A maximum of MAX_PROCESSES processes can participate */
21     if ( size > MAX_PROCESSES ) participants = MAX_PROCESSES;
22     else              participants = size;
23     /* while (MAX_PROCESSES % participants) participants--; */
24     if (MAX_PROCESSES % participants) {
25         fprintf( stderr, "Number of processors must divide %d\n",
26                 MAX_PROCESSES );
27         MPI_Abort( MPI_COMM_WORLD, 1 );
28         }
29     if ( (rank < participants) ) {
30
31       /* Determine what rows are my responsibility */
32       int block_size = MAX_PROCESSES / participants;
33       int begin_row  = rank * block_size;
34       int end_row    = (rank+1) * block_size;
35       int send_count = block_size * MAX_PROCESSES;
36       
37       /* Fill in the displacements and recv_counts */
38       for (i=0; i<participants; i++) {
39         displs[i]      = i * block_size * MAX_PROCESSES;
40         recv_counts[i] = send_count;
41       }
42
43       /* Paint my rows my color */
44       for (i=begin_row; i<end_row ;i++)
45         for (j=0; j<MAX_PROCESSES; j++)
46           table[i][j] = rank + 10;
47       
48       /* Everybody gets the gathered data */
49       MPI_Allgatherv(&table[begin_row][0], send_count, MPI_INT, 
50                      &table[0][0], recv_counts, displs, 
51                      MPI_INT, MPI_COMM_WORLD);
52
53       /* Everybody should have the same table now.
54
55          The entries are:
56          Table[i][j] = (i/block_size) + 10;
57        */
58       for (i=0; i<MAX_PROCESSES;i++) 
59         if ( (table[i][0] - table[i][MAX_PROCESSES-1] !=0) ) 
60           errors++;
61       for (i=0; i<MAX_PROCESSES;i++) {
62           for (j=0; j<MAX_PROCESSES;j++) {
63               if (table[i][j] != (i/block_size) + 10) errors++;
64               }
65           }
66       if (errors) {
67           /* Print out table if there are any errors */
68           for (i=0; i<MAX_PROCESSES;i++) {
69               printf("\n");
70               for (j=0; j<MAX_PROCESSES; j++)
71                   printf("  %d",table[i][j]);
72               }
73           printf("\n");
74           }
75     } 
76
77     Test_Waitforall( );
78     MPI_Finalize();
79     if (errors)
80       printf( "[%d] done with ERRORS(%d)!\n", rank, errors );
81     return errors;
82 }