|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2009 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
static char MTEST_Descrip[] = "A simple test of MPI_Op_create/commute/free";
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static int errs = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
static void comm_user_op(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
user_op(invec, inoutvec, len, datatype);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
static void noncomm_user_op(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
user_op(invec, inoutvec, len, datatype);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static void user_op(void *invec, void *inoutvec, int *len, MPI_Datatype * datatype)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int i;
|
|
Packit Service |
c5cf8c |
int *invec_int = (int *) invec;
|
|
Packit Service |
c5cf8c |
int *inoutvec_int = (int *) inoutvec;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (*datatype != MPI_INT) {
|
|
Packit Service |
c5cf8c |
++errs;
|
|
Packit Service |
c5cf8c |
printf("invalid datatype passed to user_op");
|
|
Packit Service |
c5cf8c |
return;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < *len; ++i) {
|
|
Packit Service |
c5cf8c |
inoutvec_int[i] = invec_int[i] * 2 + inoutvec_int[i];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPI_Op c_uop = MPI_OP_NULL;
|
|
Packit Service |
c5cf8c |
MPI_Op nc_uop = MPI_OP_NULL;
|
|
Packit Service |
c5cf8c |
int is_commutative = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* make sure that user-define ops work too */
|
|
Packit Service |
c5cf8c |
MPI_Op_create(&user_op, 1 /*commute */ , &c_uop);
|
|
Packit Service |
c5cf8c |
MPI_Op_create(&user_op, 0 /*!commute */ , &nc_uop);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if MTEST_HAVE_MIN_MPI_VERSION(2,2)
|
|
Packit Service |
c5cf8c |
/* this function was added in MPI-2.2 */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define CHECK_COMMUTATIVE(op_) \
|
|
Packit Service |
c5cf8c |
do { \
|
|
Packit Service |
c5cf8c |
MPI_Op_commutative((op_), &is_commutative); \
|
|
Packit Service |
c5cf8c |
if (!is_commutative) { ++errs; } \
|
|
Packit Service |
c5cf8c |
} while (0)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Check all predefined reduction operations for commutivity.
|
|
Packit Service |
c5cf8c |
* This list is from section 5.9.2 of the MPI-2.1 standard */
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_MAX);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_MIN);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_SUM);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_PROD);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_LAND);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_BAND);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_LOR);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_BOR);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_LXOR);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_BXOR);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_MAXLOC);
|
|
Packit Service |
c5cf8c |
CHECK_COMMUTATIVE(MPI_MINLOC);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef CHECK_COMMUTATIVE
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Op_commutative(c_uop, &is_commutative);
|
|
Packit Service |
c5cf8c |
if (!is_commutative) {
|
|
Packit Service |
c5cf8c |
++errs;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* also check our non-commutative user defined operation */
|
|
Packit Service |
c5cf8c |
MPI_Op_commutative(nc_uop, &is_commutative);
|
|
Packit Service |
c5cf8c |
if (is_commutative) {
|
|
Packit Service |
c5cf8c |
++errs;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Op_free(&nc_uop);
|
|
Packit Service |
c5cf8c |
MPI_Op_free(&c_uop);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|