Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix warnings about unused variables in mpich3-test.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / op_commutative.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2009 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[] = "A simple test of MPI_Op_create/commute/free";
14 */
15
16 static int errs = 0;
17
18 /*
19 static void comm_user_op(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
20 {
21     user_op(invec, inoutvec, len, datatype);
22 }
23 */
24
25 /*
26 static void noncomm_user_op(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
27 {
28     user_op(invec, inoutvec, len, datatype);
29 }
30 */
31
32 static void user_op(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
33 {
34     int i;
35     int *invec_int = (int *)invec;
36     int *inoutvec_int = (int *)inoutvec;
37
38     if (*datatype != MPI_INT) {
39         ++errs;
40         printf("invalid datatype passed to user_op");
41         return;
42     }
43
44     for (i = 0; i < *len; ++i) {
45         inoutvec_int[i] = invec_int[i] * 2 + inoutvec_int[i];
46     }
47 }
48
49
50 int main( int argc, char *argv[] )
51 {
52     MPI_Op c_uop = MPI_OP_NULL;
53     MPI_Op nc_uop = MPI_OP_NULL;
54 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
55     int is_commutative = 0;
56 #endif
57
58     MTest_Init(&argc, &argv);
59
60     /* make sure that user-define ops work too */
61     MPI_Op_create(&user_op, 1/*commute*/,  &c_uop);
62     MPI_Op_create(&user_op, 0/*!commute*/, &nc_uop);
63
64 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
65     /* this function was added in MPI-2.2 */
66
67 #define CHECK_COMMUTATIVE(op_)                      \
68     do {                                            \
69         MPI_Op_commutative((op_), &is_commutative); \
70         if (!is_commutative) { ++errs; }            \
71     } while (0)
72
73     /* Check all predefined reduction operations for commutivity.
74      * This list is from section 5.9.2 of the MPI-2.1 standard */
75     CHECK_COMMUTATIVE(MPI_MAX);
76     CHECK_COMMUTATIVE(MPI_MIN);
77     CHECK_COMMUTATIVE(MPI_SUM);
78     CHECK_COMMUTATIVE(MPI_PROD);
79     CHECK_COMMUTATIVE(MPI_LAND);
80     CHECK_COMMUTATIVE(MPI_BAND);
81     CHECK_COMMUTATIVE(MPI_LOR);
82     CHECK_COMMUTATIVE(MPI_BOR);
83     CHECK_COMMUTATIVE(MPI_LXOR);
84     CHECK_COMMUTATIVE(MPI_BXOR);
85     CHECK_COMMUTATIVE(MPI_MAXLOC);
86     CHECK_COMMUTATIVE(MPI_MINLOC);
87
88 #undef CHECK_COMMUTATIVE
89
90     MPI_Op_commutative(c_uop, &is_commutative);
91     if (!is_commutative) {
92         ++errs;
93     }
94
95     /* also check our non-commutative user defined operation */
96     MPI_Op_commutative(nc_uop, &is_commutative);
97     if (is_commutative) {
98         ++errs;
99     }
100 #endif
101
102     MPI_Op_free(&nc_uop);
103     MPI_Op_free(&c_uop);
104
105     MTest_Finalize(errs);
106     MPI_Finalize();
107     return 0;
108 }
109