Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / exscan2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test MPI_Exscan (simple test)";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0;
19     int rank, size;
20     int sendbuf[1], recvbuf[1];
21     MPI_Comm      comm;
22
23     MTest_Init( &argc, &argv );
24
25     comm = MPI_COMM_WORLD;
26     MPI_Comm_rank( comm, &rank );
27     MPI_Comm_size( comm, &size );
28     
29     sendbuf[0] = rank;
30     recvbuf[0] = -2;
31             
32     MPI_Exscan( sendbuf, recvbuf, 1, MPI_INT, MPI_SUM, comm );
33
34     /* Check the results.  rank 0 has no data.  Input is
35        0  1  2  3  4  5  6  7  8 ...
36        Output is
37        -  0  1  3  6 10 15 21 28 36
38        (scan, not counting the contribution from the calling process)
39     */
40     if (rank > 0) {
41         int result = (((rank) * (rank-1))/2);
42         /* printf( "%d: %d\n", rank, result ); */
43         if (recvbuf[0] != result) {
44             errs++;
45             fprintf( stderr, "Error in recvbuf = %d on %d, expected %d\n",
46                          recvbuf[0], rank, result );
47         }
48     }
49     else if (recvbuf[0] != -2) {
50         errs++;
51         fprintf( stderr, "Error in recvbuf on zero, is %d\n", recvbuf[0] );
52     }
53
54     MTest_Finalize( errs );
55     MPI_Finalize();
56     return 0;
57 }