Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / coll10.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include "mpitest.h"
9
10 #define BAD_ANSWER 100000
11
12 /*
13     The operation is inoutvec[i] = invec[i] op inoutvec[i]
14     (see 4.9.4).  The order is important.
15
16     Note that the computation is in process rank (in the communicator)
17     order, independent of the root.
18  */
19 static void assoc(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype)
20 {
21     int i;
22     for (i = 0; i < *len; i++) {
23         if (inoutvec[i] <= invec[i]) {
24             int rank;
25             MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26             fprintf(stderr, "[%d] inout[0] = %d, in[0] = %d\n", rank, inoutvec[0], invec[0]);
27             inoutvec[i] = BAD_ANSWER;
28         }
29         else
30             inoutvec[i] = invec[i];
31     }
32 }
33
34 int main(int argc, char **argv)
35 {
36     int rank, size;
37     int data;
38     int errors = 0;
39     int result = -100;
40     MPI_Op op;
41
42     MTest_Init(&argc, &argv);
43     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
44     MPI_Comm_size(MPI_COMM_WORLD, &size);
45
46     data = rank;
47
48     MPI_Op_create((MPI_User_function *) assoc, 0, &op);
49     MPI_Reduce(&data, &result, 1, MPI_INT, op, size - 1, MPI_COMM_WORLD);
50     MPI_Bcast(&result, 1, MPI_INT, size - 1, MPI_COMM_WORLD);
51     MPI_Op_free(&op);
52     if (result == BAD_ANSWER)
53         errors++;
54
55     MTest_Finalize(errors);
56     MPI_Finalize();
57     return MTestReturnValue(errors);
58 }