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 / coll5.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     int              displs[MAX_PROCESSES];
15     int              send_counts[MAX_PROCESSES];
16
17     MPI_Init( &argc, &argv );
18     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
19     MPI_Comm_size( MPI_COMM_WORLD, &size );
20
21     /* A maximum of MAX_PROCESSES processes can participate */
22     if ( size > MAX_PROCESSES ) participants = MAX_PROCESSES;
23     else              participants = size;
24     if ( (rank < participants) ) {
25       int recv_count = MAX_PROCESSES;
26       
27       /* If I'm the root (process 0), then fill out the big table */
28       /* and setup  send_counts and displs arrays */
29       if (rank == 0) 
30         for ( i=0; i<participants; i++) {
31           send_counts[i] = recv_count;
32           displs[i] = i * MAX_PROCESSES;
33           for ( j=0; j<MAX_PROCESSES; j++ ) 
34             table[i][j] = i+j;
35         }
36       
37       /* Scatter the big table to everybody's little table */
38       MPI_Scatterv(&table[0][0], send_counts, displs, MPI_INT, 
39                    &row[0]     , recv_count, MPI_INT, 0, MPI_COMM_WORLD);
40
41       /* Now see if our row looks right */
42       for (i=0; i<MAX_PROCESSES; i++) 
43         if ( row[i] != i+rank ) errors++;
44     } 
45
46     Test_Waitforall( );
47     MPI_Finalize();
48     if (errors)
49       printf( "[%d] done with ERRORS(%d)!\n", rank, errors );
50     return errors;
51 }