1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2009 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
13 static char MTEST_Descrip[] = "A simple test of MPI_Reduce_local";
16 #define MAX_BUF_ELEMENTS (65000)
18 static int uop_errs = 0;
20 /* prototype to keep the compiler happy */
21 static void user_op(void *invec, void *inoutvec, int *len, MPI_Datatype * datatype);
23 static void user_op(void *invec, void *inoutvec, int *len, MPI_Datatype * datatype)
26 int *invec_int = (int *) invec;
27 int *inoutvec_int = (int *) inoutvec;
29 if (*datatype != MPI_INT) {
31 printf("invalid datatype passed to user_op");
35 for (i = 0; i < *len; ++i) {
36 inoutvec_int[i] = invec_int[i] * 2 + inoutvec_int[i];
40 int main(int argc, char *argv[])
47 MPI_Op uop = MPI_OP_NULL;
49 MTest_Init(&argc, &argv);
50 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
51 /* this function was added in MPI-2.2 */
53 inbuf = malloc(sizeof(int) * MAX_BUF_ELEMENTS);
54 inoutbuf = malloc(sizeof(int) * MAX_BUF_ELEMENTS);
56 for (count = 0; count < MAX_BUF_ELEMENTS; count > 0 ? count *= 2 : count++) {
57 for (i = 0; i < count; ++i) {
61 MPI_Reduce_local(inbuf, inoutbuf, count, MPI_INT, MPI_SUM);
62 for (i = 0; i < count; ++i)
65 if (inoutbuf[i] != (2 * i))
70 /* make sure that user-define ops work too */
71 MPI_Op_create(&user_op, 0 /*!commute */ , &uop);
72 for (count = 0; count < MAX_BUF_ELEMENTS; count > 0 ? count *= 2 : count++) {
73 for (i = 0; i < count; ++i) {
77 MPI_Reduce_local(inbuf, inoutbuf, count, MPI_INT, uop);
79 for (i = 0; i < count; ++i)
82 if (inoutbuf[i] != (3 * i))