1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 void addem(int *, int *, int *, MPI_Datatype *);
11 void assoc(int *, int *, int *, MPI_Datatype *);
13 void addem(int *invec, int *inoutvec, int *len, MPI_Datatype * dtype)
16 for (i = 0; i < *len; i++)
17 inoutvec[i] += invec[i];
20 #define BAD_ANSWER 100000
23 The operation is inoutvec[i] = invec[i] op inoutvec[i]
24 (see 4.9.4). The order is important.
26 Note that the computation is in process rank (in the communicator)
27 order, independant of the root.
29 void assoc(int *invec, int *inoutvec, int *len, MPI_Datatype * dtype)
32 for (i = 0; i < *len; i++) {
33 if (inoutvec[i] <= invec[i]) {
35 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
36 fprintf(stderr, "[%d] inout[0] = %d, in[0] = %d\n", rank, inoutvec[0], invec[0]);
37 inoutvec[i] = BAD_ANSWER;
40 inoutvec[i] = invec[i];
44 int main(int argc, char **argv)
51 MPI_Op op_assoc, op_addem;
53 MTest_Init(&argc, &argv);
54 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
55 MPI_Comm_size(MPI_COMM_WORLD, &size);
60 for (i = 0; i <= rank; i++)
63 MPI_Scan(&data, &result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
64 if (result != correct_result) {
65 fprintf(stderr, "[%d] Error suming ints with scan\n", rank);
69 MPI_Scan(&data, &result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
70 if (result != correct_result) {
71 fprintf(stderr, "[%d] Error summing ints with scan (2)\n", rank);
77 MPI_Op_create((MPI_User_function *) assoc, 0, &op_assoc);
78 MPI_Op_create((MPI_User_function *) addem, 1, &op_addem);
79 MPI_Scan(&data, &result, 1, MPI_INT, op_addem, MPI_COMM_WORLD);
80 if (result != correct_result) {
81 fprintf(stderr, "[%d] Error summing ints with scan (userop)\n", rank);
85 MPI_Scan(&data, &result, 1, MPI_INT, op_addem, MPI_COMM_WORLD);
86 if (result != correct_result) {
87 fprintf(stderr, "[%d] Error summing ints with scan (userop2)\n", rank);
92 MPI_Scan(&data, &result, 1, MPI_INT, op_assoc, MPI_COMM_WORLD);
93 if (result == BAD_ANSWER) {
94 fprintf(stderr, "[%d] Error scanning with non-commutative op\n", rank);
98 MPI_Op_free(&op_assoc);
99 MPI_Op_free(&op_addem);
101 MTest_Finalize(errors);
103 return MTestReturnValue(errors);