Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add reduce scatter collectives from openmpi, and fix existing one
[simgrid.git] / teshsuite / smpi / mpich-test / coll / redscat.c
1 /* 
2  * Test of reduce scatter.
3  *
4  * Each processor contributes its rank + the index to the reduction, 
5  * then receives the ith sum
6  *
7  * Can be called with any number of processors.
8  */
9
10 #include "mpi.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include "test.h"
14
15 int main( int argc, char **argv )
16 {
17     int      err = 0, toterr;
18     int      *sendbuf, *recvbuf, *recvcounts;
19     int      size, rank, i, sumval;
20     MPI_Comm comm;
21
22
23     MPI_Init( &argc, &argv );
24     comm = MPI_COMM_WORLD;
25
26     MPI_Comm_size( comm, &size );
27     MPI_Comm_rank( comm, &rank );
28     sendbuf = (int *) malloc( size * sizeof(int) );
29     for (i=0; i<size; i++) 
30         sendbuf[i] = rank + i;
31     recvcounts = (int *)malloc( size * sizeof(int) );
32         recvbuf = (int *)malloc( size * sizeof(int) );
33     for (i=0; i<size; i++) 
34     recvcounts[i] = 1;
35     MPI_Reduce_scatter( sendbuf, recvbuf, recvcounts, MPI_INT, MPI_SUM, comm );
36     sumval = size * rank + ((size - 1) * size)/2;
37 /* recvbuf should be size * (rank + i) */
38     if (recvbuf[0] != sumval) {
39         err++;
40         fprintf( stdout, "Did not get expected value for reduce scatter\n" );
41         fprintf( stdout, "[%d] Got %d expected %d\n", rank, recvbuf[0], sumval );
42     }
43
44     MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
45     if (rank == 0 && toterr == 0) {
46         printf( " No Errors\n" );
47     }
48     MPI_Finalize( );
49
50     return toterr;
51 }