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[] )
43 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
48 MPI_Op uop = MPI_OP_NULL;
51 MTest_Init(&argc, &argv);
52 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
53 /* this function was added in MPI-2.2 */
55 inbuf = malloc(sizeof(int) * MAX_BUF_ELEMENTS);
56 inoutbuf = malloc(sizeof(int) * MAX_BUF_ELEMENTS);
58 for (count = 0; count < MAX_BUF_ELEMENTS; count > 0 ? count*=2 : count++) {
59 for (i = 0; i < count; ++i) {
63 MPI_Reduce_local(inbuf, inoutbuf, count, MPI_INT, MPI_SUM);
64 for (i = 0; i < count; ++i)
67 if (inoutbuf[i] != (2*i))
72 /* make sure that user-define ops work too */
73 MPI_Op_create(&user_op, 0/*!commute*/, &uop);
74 for (count = 0; count < MAX_BUF_ELEMENTS; count > 0 ? count*=2 : count++) {
75 for (i = 0; i < count; ++i) {
79 MPI_Reduce_local(inbuf, inoutbuf, count, MPI_INT, uop);
81 for (i = 0; i < count; ++i)
84 if (inoutbuf[i] != (3*i))