LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Jeff Squyres (jsquyres_at_[hidden])
Date: 2003-07-16 09:49:18


On Wed, 16 Jul 2003, William Boatin wrote:

> >WB> for (iSlave = 1; iSlave < iSize; iSlave++)
> >WB> {
> >WB> // build handles for the receipt of results
>
>
> >Shouldn't this be "for (iSlave = 0;... " ?
>
> the number '0' is the rank of the process. my master process is rank 0,
> so i wanna initiate receives from the slave processes which start from
> 1.

This is a C problem, not an MPI problem.

When you start the loop at 1, you're effectively leaving
mastersRequests[0] uninitialized. Then you're invoking

        MPI_Startall(iSize - 1, mastersRequests);

and telling MPI that mastersRequests[0] is a valid request. You either
need to fill your array starting with index 0 (as far as MPI is concerned,
the index of the array is unrelated to the rank with which you are
communicating), or you need to waste the 0th position and tell MPI to look
at (mastersRequests+1):

        MPI_Startall(iSize - 1, mastersRequests + 1);

It can be argued either way: it's definitely more efficient to not waste a
slot in the array, but it's clearer code to have the rank correspond to
the index.

-- 
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/