16 void runTest(
int ndoubles, MPI_Comm &comm)
19 MPI_Comm_rank(comm, &me);
20 MPI_Comm_size(comm, &np);
22 double *sendBuf =
new double[ndoubles];
23 for (
int i = 0; i < ndoubles; i++) sendBuf[i] = 0.;
24 int nMy = ndoubles / np + (me < (ndoubles % np));
25 int myBegin = (ndoubles / np) * me;
26 myBegin += ((ndoubles % np) < me ? (ndoubles % np) : me);
27 int myEnd = myBegin + nMy;
28 for (
int i = myBegin; i < myEnd; ++i) sendBuf[i] = me;
30 double *recvBuf =
new double[ndoubles];
33 std::cout <<
"Trying reduceAll with ndoubles = " << ndoubles << std::endl;
35 MPI_Allreduce(sendBuf, recvBuf, ndoubles, MPI_DOUBLE, MPI_SUM, comm);
42 int main(
int narg,
char **arg)
44 MPI_Init(&narg, &arg);
45 MPI_Comm comm = MPI_COMM_WORLD;
48 MPI_Comm_rank(comm, &me);
52 std::cout <<
"Usage: a.out [Y|N] \n"
53 <<
" a.out Y ==> duplicate communicator \n"
54 <<
" a.out N ==> do not duplicate communicator \n"
59 bool dupComm = (arg[1][0] ==
'Y' ?
true :
false);
63 MPI_Comm_dup(comm, &commdup);
68 std::cout <<
"PASSED with "
69 << (dupComm ?
"comm duplication " :
"no comm duplication ")
72 if (dupComm) MPI_Comm_free(&commdup);
void runTest(int ndoubles, MPI_Comm &comm)
int main(int argc, char *argv[])