|
Packit Service |
c5cf8c |
/* -*- Mode: C++; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2014 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Test of reduce scatter with large data (needed in MPICH to trigger the
|
|
Packit Service |
c5cf8c |
* long-data algorithm)
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Each processor contributes its rank + the index to the reduction,
|
|
Packit Service |
c5cf8c |
* then receives the ith sum
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Can be called with any number of processors.
|
|
Packit Service |
c5cf8c |
*/
|
|
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 "mpitestconf.h"
|
|
Packit Service |
c5cf8c |
#include "mpitestcxx.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int err = 0;
|
|
Packit Service |
c5cf8c |
int *sendbuf, *recvbuf;
|
|
Packit Service |
c5cf8c |
int size, rank, i, j, idx, mycount, sumval;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::Init();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
size = MPI::COMM_WORLD.Get_size();
|
|
Packit Service |
c5cf8c |
rank = MPI::COMM_WORLD.Get_rank();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mycount = (1024 * 1024) / size;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sendbuf = new int[mycount * size];
|
|
Packit Service |
c5cf8c |
idx = 0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < size; i++) {
|
|
Packit Service |
c5cf8c |
for (j = 0; j < mycount; j++) {
|
|
Packit Service |
c5cf8c |
sendbuf[idx++] = rank + i;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
recvbuf = new int[mycount];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Reduce_scatter_block(sendbuf, recvbuf, mycount, MPI::INT, MPI::SUM);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sumval = size * rank + ((size - 1) * size) / 2;
|
|
Packit Service |
c5cf8c |
/* recvbuf should be size * (rank + i) */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < mycount; i++) {
|
|
Packit Service |
c5cf8c |
if (recvbuf[i] != sumval) {
|
|
Packit Service |
c5cf8c |
err++;
|
|
Packit Service |
c5cf8c |
fprintf(stdout, "Did not get expected value for reduce scatter\n");
|
|
Packit Service |
c5cf8c |
fprintf(stdout, "[%d] Got %d expected %d\n", rank, recvbuf[i], sumval);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Reduce_scatter_block(MPI_IN_PLACE, sendbuf, mycount, MPI::INT, MPI::SUM);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sumval = size * rank + ((size - 1) * size) / 2;
|
|
Packit Service |
c5cf8c |
/* recv'ed values for my process should be size * (rank + i) */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < mycount; i++) {
|
|
Packit Service |
c5cf8c |
if (sendbuf[rank * mycount + i] != sumval) {
|
|
Packit Service |
c5cf8c |
err++;
|
|
Packit Service |
c5cf8c |
fprintf(stdout, "Did not get expected value for reduce scatter (in place)\n");
|
|
Packit Service |
c5cf8c |
fprintf(stdout, "[%d] Got %d expected %d\n", rank, sendbuf[rank * mycount + i], sumval);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
delete[]sendbuf;
|
|
Packit Service |
c5cf8c |
delete[]recvbuf;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(err);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|