LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Brian Barrett (brbarret_at_[hidden])
Date: 2003-08-24 17:00:08


On Monday, August 18, 2003, at 07:06 PM, Carlos Lopez Nataren wrote:

> Hello, I am trying to do a very simple task but I've tried everything
> and I can't
> seem to find the answer, can anyone please help me???
>
> int points [10];
> int max_value;
> MPI_Reduce(&points, &max_value, 10, MPI_INT, MPI_MAX, 0,
> MPI_COMM_WORLD);

Please excuse the liberal cutting of your e-mail :).

I think the problem is that your expectation of MPI_Reduce and what it
actually does don't quite match. MPI_Reduce works with arrays - both
in and out. So the correct code snippet would be:

int points[10];
int max_value[10];
MPI_Reduce(&points, &max_value, 10, MPI_INT, MPI_MAX, 0,
MPI_COMM_WORLD);

Each element of max_value contains the maximum value from that index
into points from each process that called MPI_REDUCE. So to get the
maximum value of all values of points everywhere, you then have to find
the maximum value stored in max_value.

Hope this helps,

Brian

-- 
   Brian Barrett
   LAM/MPI developer and all around nice guy
   Have a LAM/MPI day: http://www.lam-mpi.org/