|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2012 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Test user-defined operations with a large number of elements.
|
|
Packit Service |
c5cf8c |
* Added because a talk at EuroMPI'12 claimed that these failed with
|
|
Packit Service |
c5cf8c |
* more than 64k elements
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MAX_ERRS 10
|
|
Packit Service |
c5cf8c |
#define MAX_COUNT 1200000
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
void myop(void *cinPtr, void *coutPtr, int *count, MPI_Datatype * dtype);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* myop takes a datatype that is a triple of doubles, and computes
|
|
Packit Service |
c5cf8c |
* the sum, max, min of the respective elements of the triple.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
void myop(void *cinPtr, void *coutPtr, int *count, MPI_Datatype * dtype)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int i, n = *count;
|
|
Packit Service |
c5cf8c |
double const *cin = (double *) cinPtr;
|
|
Packit Service |
c5cf8c |
double *cout = (double *) coutPtr;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < n; i++) {
|
|
Packit Service |
c5cf8c |
cout[0] += cin[0];
|
|
Packit Service |
c5cf8c |
cout[1] = (cout[1] > cin[1]) ? cout[1] : cin[1];
|
|
Packit Service |
c5cf8c |
cout[2] = (cout[2] < cin[2]) ? cout[2] : cin[2];
|
|
Packit Service |
c5cf8c |
cin += 3;
|
|
Packit Service |
c5cf8c |
cout += 3;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int errs = 0;
|
|
Packit Service |
c5cf8c |
int wsize, wrank, i, count;
|
|
Packit Service |
c5cf8c |
MPI_Datatype tripleType;
|
|
Packit Service |
c5cf8c |
double *inVal, *outVal;
|
|
Packit Service |
c5cf8c |
double maxval, sumval, minval;
|
|
Packit Service |
c5cf8c |
MPI_Op op;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Op_create(myop, 0, &op);
|
|
Packit Service |
c5cf8c |
MPI_Type_contiguous(3, MPI_DOUBLE, &tripleType);
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&tripleType);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (count = 1; count < MAX_COUNT; count += count) {
|
|
Packit Service |
c5cf8c |
if (wrank == 0)
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(1, "Count = %d\n", count);
|
|
Packit Service |
c5cf8c |
inVal = (double *) malloc(3 * count * sizeof(double));
|
|
Packit Service |
c5cf8c |
outVal = (double *) malloc(3 * count * sizeof(double));
|
|
Packit Service |
c5cf8c |
if (!inVal || !outVal) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Unable to allocate %d words for data\n", 3 * count);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
for (i = 0; i < count * 3; i++) {
|
|
Packit Service |
c5cf8c |
outVal[i] = -1;
|
|
Packit Service |
c5cf8c |
inVal[i] = 1 + (i & 0x3);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Reduce(inVal, outVal, count, tripleType, op, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
/* Check Result values */
|
|
Packit Service |
c5cf8c |
if (wrank == 0) {
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 3 * count; i += 3) {
|
|
Packit Service |
c5cf8c |
sumval = wsize * (1 + (i & 0x3));
|
|
Packit Service |
c5cf8c |
maxval = 1 + ((i + 1) & 0x3);
|
|
Packit Service |
c5cf8c |
minval = 1 + ((i + 2) & 0x3);
|
|
Packit Service |
c5cf8c |
if (outVal[i] != sumval) {
|
|
Packit Service |
c5cf8c |
if (errs < MAX_ERRS)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%d: outval[%d] = %f, expected %f (sum)\n",
|
|
Packit Service |
c5cf8c |
count, i, outVal[i], sumval);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (outVal[i + 1] != maxval) {
|
|
Packit Service |
c5cf8c |
if (errs < MAX_ERRS)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%d: outval[%d] = %f, expected %f (max)\n",
|
|
Packit Service |
c5cf8c |
count, i + 1, outVal[i + 1], maxval);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (outVal[i + 2] != minval) {
|
|
Packit Service |
c5cf8c |
if (errs < MAX_ERRS)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%d: outval[%d] = %f, expected %f (min)\n",
|
|
Packit Service |
c5cf8c |
count, i + 2, outVal[i + 2], minval);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(inVal);
|
|
Packit Service |
c5cf8c |
free(outVal);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Op_free(&op);
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&tripleType);
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|