Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This used to work by accident
[simgrid.git] / teshsuite / smpi / mpich-test / coll / coll4.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              row[MAX_PROCESSES];
12     int              errors=0;
13     int              participants;
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     if ( (rank < participants) ) {
23       int send_count = MAX_PROCESSES;
24       int recv_count = MAX_PROCESSES;
25
26       /* If I'm the root (process 0), then fill out the big table */
27       if (rank == 0) 
28         for ( i=0; i<participants; i++) 
29           for ( j=0; j<MAX_PROCESSES; j++ ) 
30             table[i][j] = i+j;
31       
32       /* Scatter the big table to everybody's little table */
33       MPI_Scatter(&table[0][0], send_count, MPI_INT, 
34                   &row[0]     , recv_count, MPI_INT, 0, MPI_COMM_WORLD);
35
36       /* Now see if our row looks right */
37       for (i=0; i<MAX_PROCESSES; i++) 
38         if ( row[i] != i+rank ) errors++;
39     } 
40
41     Test_Waitforall( );
42     MPI_Finalize();
43     if (errors)
44       printf( "[%d] done with ERRORS(%d)!\n", rank, errors );
45     return errors;
46 }