Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / iallred.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2012 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <assert.h>
10 #include "mpi.h"
11 #include "mpitest.h"
12
13 int main(int argc, char *argv[])
14 {
15     MPI_Request request;
16     int size, rank;
17     int one = 1, two = 2, isum, sum;
18     int errs = 0;
19
20     MPI_Init(&argc,&argv);
21     MPI_Comm_size(MPI_COMM_WORLD, &size);
22     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23     assert(size == 2);
24     MPI_Iallreduce(&one,&isum,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD,&request);
25     MPI_Allreduce(&two,&sum,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
26     MPI_Wait(&request,MPI_STATUS_IGNORE);
27
28     assert(isum == 2);
29     assert(sum == 4);
30
31     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
32     if (MPI_SUCCESS == MPI_Iallreduce(&one, &one, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &request))
33         errs++;
34
35     if (rank == 0 && errs == 0)
36         printf(" No errors\n");
37
38     MPI_Finalize();
39     return 0;
40 }
41