LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: L WK (phase2phasel_at_[hidden])
Date: 2005-08-16 10:09:01


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!?

_________________________________________________________________
ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£ http://www.hotmail.com