|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 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 |
int add(double *, double *, int *, MPI_Datatype *);
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* User-defined operation on a long value (tests proper handling of
|
|
Packit Service |
c5cf8c |
* possible pipelining in the implementation of reductions with user-defined
|
|
Packit Service |
c5cf8c |
* operations).
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
int add(double *invec, double *inoutvec, int *len, MPI_Datatype * dtype)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int i, n = *len;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < n; i++) {
|
|
Packit Service |
c5cf8c |
inoutvec[i] = invec[i] + inoutvec[i];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPI_Op op;
|
|
Packit Service |
c5cf8c |
int i, rank, size, bufsize, errcnt = 0;
|
|
Packit Service |
c5cf8c |
double *inbuf, *outbuf, value;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit Service |
c5cf8c |
MPI_Op_create((MPI_User_function *) add, 1, &op);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
bufsize = 1;
|
|
Packit Service |
c5cf8c |
while (bufsize < 100000) {
|
|
Packit Service |
c5cf8c |
inbuf = (double *) malloc(bufsize * sizeof(double));
|
|
Packit Service |
c5cf8c |
outbuf = (double *) malloc(bufsize * sizeof(double));
|
|
Packit Service |
c5cf8c |
if (!inbuf || !outbuf) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Could not allocate buffers for size %d\n", bufsize);
|
|
Packit Service |
c5cf8c |
errcnt++;
|
|
Packit Service |
c5cf8c |
break;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
value = (rank & 0x1) ? 1.0 : -1.0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < bufsize; i++) {
|
|
Packit Service |
c5cf8c |
inbuf[i] = value;
|
|
Packit Service |
c5cf8c |
outbuf[i] = 100.0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Allreduce(inbuf, outbuf, bufsize, MPI_DOUBLE, op, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
/* Check values */
|
|
Packit Service |
c5cf8c |
value = (size & 0x1) ? -1.0 : 0.0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < bufsize; i++) {
|
|
Packit Service |
c5cf8c |
if (outbuf[i] != value) {
|
|
Packit Service |
c5cf8c |
if (errcnt < 10)
|
|
Packit Service |
c5cf8c |
printf("outbuf[%d] = %f, should = %f\n", i, outbuf[i], value);
|
|
Packit Service |
c5cf8c |
errcnt++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
free(inbuf);
|
|
Packit Service |
c5cf8c |
free(outbuf);
|
|
Packit Service |
c5cf8c |
bufsize *= 2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Op_free(&op);
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errcnt);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errcnt);
|
|
Packit Service |
c5cf8c |
}
|