[MPICH] RE: (ÈðÐÇÌáʾ-´ËÓʼþ¿ÉÄÜÊÇÀ¬»øÓʼþ)RE: [MPICH] about MPI_Reduce

Rajeev Thakur thakur at mcs.anl.gov
Mon Oct 17 13:16:46 CDT 2005


MPI will pass the buf, count, datatype arguments directly to your reduction function without doing anything with them. So in your example, the entire buffer will be passed to myReFn. It it up to myReFn to do the noncontiguous reduction. See this section of the spec at http://www.mpi-forum.org/docs/mpi-11-html/node80.html

 "The datatype argument is a handle to the data type that was passed into the call to MPI_REDUCE. The user reduce function should be written such that the following holds: Let u[0], ... , u[len-1] be the len elements in the communication buffer described by the arguments invec, len and datatype when the function is invoked; let v[0], ... , v[len-1] be len elements in the communication buffer described by the arguments inoutvec, len and datatype when the function is invoked; let w[0], ... , w[len-1] be len elements in the communication buffer described by the arguments inoutvec, len and datatype when the function returns; then w[i] = u[i] v[i], for i=0 , ... , len-1, where  is the reduce operation that the function computes."

See also the section under Advice to Users.

Rajeev 
 

> -----Original Message-----
> From: llwaeva at 21cn.com [mailto:llwaeva at 21cn.com] 
> Sent: Monday, October 17, 2005 12:28 PM
> To: Rajeev Thakur; mpich
> Subject: Re: (瑞星提示-此邮件可能是垃圾邮件)RE: [MPICH] about MPI_Reduce
> 
> > If you use a derived datatype, you need to provide the 
> reduction function
> > that does the reduction operation locally on the derived 
> datatype. MPI will
> > do the communication and call this function to do the 
> reduction. So if the
> > reduction is not happening, the myOp function you provide 
> is probably not
> > right.
> I don't know what's going on. It seems that the reduction 
> function never
> know the structure of the derived datatype. Moreover, the entry of the
> data sent to the reduction function is not valid. 
> 
> Suppose the data list is
> 
> buffer=[0 1 2 3 4 5 6 7 8]
> 
> mydatatype is a derived type which hold the data in even index, i.e.
> from mydatatype, we get [0 2 4 6 8]
> 
> MPI_Reduce( &buffer, &output, 1, mydatatype, myOp, 0, 
> MPI_COMM_WORLD); 
> 
> The self-defined reduction function is
> 
> void myReFun(int *in, int *inout, int *len, MPI_Datatype *dptr)
> { int i;
> 
>   for (i=0; i<8; i++)
>   { 
>     if (i%2==0) 
>     {
>       printf("%d\n", *in); fflush(stdout);
>       *inout = 2*(*in);
>     }
>     in++; inout++;
>   }
> }
> 
> Anything wrong?
> 
> 
> 




More information about the mpich-discuss mailing list