[mpich-discuss] MPI_Reduce syntax
Martin Siegert
siegert at sfu.ca
Mon Dec 7 22:41:39 CST 2009
Hi,
the MPI standard
http://www.mpi-forum.org/docs/mpi22-report/node103.htm#Node103
says the following about MPI_Reduce:
"The routine is called by all group members using the same arguments for
count, datatype, op, root and comm. Thus, all processes provide input
buffers and output buffers of the same length, with elements of the
same type."
Thus, the following appears to be illegal:
buf = (double *)malloc(l*sizeof(double);
random(buf, l); /* fill buf with something */
if (myid == 0) {
MPI_Reduce(MPI_IN_PLACE, buf, l, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
} else {
MPI_Reduce(buf, NULL, l, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
}
because it violates the "same length" requirement of input and output
buffers. But why do I need to provide a valid output buffer for processes
other than the receiving one?
Will the code using NULL as the receive buffer for those processes
that do not receive anything work with mpich2?
Cheers,
Martin
--
Martin Siegert
Head, Research Computing
WestGrid Site Lead
IT Services phone: 778 782-4691
Simon Fraser University fax: 778 782-4242
Burnaby, British Columbia email: siegert at sfu.ca
Canada V5A 1S6
More information about the mpich-discuss
mailing list