/** * Test MPI_Reduce with a user-defined reduction function * * Author: Thomas Moschny */ #include #include #include int const vlength=8; void reduction(int *in, int *inout, int *len, MPI_Datatype *dptr); MPI_Datatype datatype; int main(int argc, char** argv) { /* initialization */ int rank = -1; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* create our own type */ MPI_Type_vector(vlength/2, 1, 2, MPI_INT, &datatype); MPI_Type_commit(&datatype); /* create our own operator */ MPI_Op op; MPI_Op_create((MPI_User_function*)reduction, 1, &op); /* create the arrays */ int src[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; int dst[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; /* reduce */ MPI_Reduce(src, dst, 1, datatype, op, 0, MPI_COMM_WORLD); /* print */ if (rank==0){ for (int i=0; i