[MPICH] about MPI_Reduce

llwaeva at 21cn.com llwaeva at 21cn.com
Tue Oct 18 02:05:37 CDT 2005


> The attached small test program produces the expected output with mpich-1.2.6:
> $ mpicc -Wall -W -Wno-unused -O2 -g -std=c99 reduce.c -o reduce
> $ mpirun -np 10 ./reduce
> 10 0 30 0 50 0 70 0
> 
> BTW: Identical output is produced when I compile and run the program with
> LAM 7.1.1.
> 
Thanks for your program. It does work. I found the problem is in the
reduction function. In your code, everything is all right

void reduction(int *in, int *inout, int *len, MPI_Datatype *dptr)
{
  assert(*dptr == datatype);
  for (int l=0; l<(*len); l++)
    for (int i=0; i<vlength; i++)
      if (i%2==0) inout[i] += in[i]; 
}

However, if I change the array operation to pointer operation (as the book
"MPI: The complete reference" do), the result is wrong

void reduction(int *in, int *inout, int *len, MPI_Datatype *dptr)
{ int l, i;
  assert(*dptr == datatype);
  for (l=0; l<(*len); l++)
    for (i=0; i<vlength; i++)
      if (i%2==0) {*inout += *in; inout++; in++;}
}

I am wondering what's going on




More information about the mpich-discuss mailing list