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 #define BAD_ANSWER 100000
13 The operation is inoutvec[i] = invec[i] op inoutvec[i]
14 (see 4.9.4). The order is important.
16 Note that the computation is in process rank (in the communicator)
17 order, independent of the root.
19 static void assoc(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype)
22 for (i = 0; i < *len; i++) {
23 if (inoutvec[i] <= invec[i]) {
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;
30 inoutvec[i] = invec[i];
34 int main(int argc, char **argv)
42 MTest_Init(&argc, &argv);
43 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
44 MPI_Comm_size(MPI_COMM_WORLD, &size);
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);
52 if (result == BAD_ANSWER)
55 MTest_Finalize(errors);
57 return MTestReturnValue(errors);