L WK wrote:
> Hi there,
>
> I am using MPI_Reduce with a user-defined type as follow
>
> #define N 100
>
> int src[N], dest[N];
> MPI_Op myOp;
> MPI_Datatype DT;
>
> void fun(int *in, int *inout, int *len, MPI_Datatype *dptr)
> { int i;
>
> for (i=0; i<*len; ++i)
> {
> *inout = *in + 2*(*inout);
> *in++; *inout++;
> }
> }
>
> int main(int argc,char *argv[])
> {
> ...
> MPI_Type_contiguous( N, MPI_INT, &DT );
> MPI_Type_commit( &DT );
> MPI_Op_create( (void *)fun, 0, &myOp );
>
> MPI_Reduce( &src[0], &dest[0], N, MPI_INT, myOp, 0, MPI_COMM_WORLD );
>
> MPI_Reduce( &src[0], &dest[0], 1, DT, myOp, 0, MPI_COMM_WORLD );
>
> MPI_Op_free(&myOp);
> MPI_Type_free(&DT);
> ...
> return 1;
> }
>
> In the first invoked of MPI_Reduce, nothing goes wrong. However, I would
> like to define a little bit complicated type. For testing, I just use a
> contiguous type instead. DT is
> just the type contains N contiguous units as whole. So, the 'count'
> parameter of MPI_Reduce
> should be 1 instead of N when DT is given as type rather than MPI_INT
> logically. However,
> I find that in the case ONLY ONE ELEMENTS of the source buffer will be
> picked to take part
> in the calculation, i.e. the *len parameter of fun() is ONE! How is that
> happen!?
>
'count' is what is being passed into your defined function as "len".
The datatype is only used in cases where different types require
different syntax/code. That is, the function may do a switch statement
on the datatype to know what to do. MPI is not going to tell the
function anything about the datatype.
You may be able to accomplish what you want with a global variable or by
encoding in the data the number of elements. Another possibility would
involve getting the extent of the datatype and calculating how many
elements there are.
I hope this helps.
Dave.
> _________________________________________________________________
> ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£ http://www.hotmail.com
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
--
Dr. David Cronk, Ph.D. phone: (865) 974-3735
Research Leader fax: (865) 974-8296
Innovative Computing Lab http://www.cs.utk.edu/~cronk
University of Tennessee, Knoxville
|