[mpich-discuss] MPI_Reduce syntax
Dave Goodell
goodell at mcs.anl.gov
Tue Dec 8 10:06:17 CST 2009
Hi Martin,
Yes, that is valid MPI code. A key observation is that slightly
earlier in the subsection, in the description of the "recvbuf"
parameter, it says "significant only at root".
Perhaps that second sentence could be reworded to be a bit less
confusing in a future version of the MPI Standard. The sentence is
really trying to say that the send and recv buffers need to be the
same size with elements of the same type at the root, and that the
send buffers need to be the same size with elements of the same type
on all processes, including the root. I'll take a note to myself to
discuss it with others at the next meeting of the MPI Forum in January.
-Dave
On Dec 7, 2009, at 10:41 PM, Martin Siegert wrote:
> 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
> _______________________________________________
> mpich-discuss mailing list
> mpich-discuss at mcs.anl.gov
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
More information about the mpich-discuss
mailing list