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-05-14 14:32:24


On Tue, 13 May 2003, Pak, Anne O wrote:

> I am using MPI_Comm_spawn to create processes on some remote slave
> nodes. The C program that gets spawned on these remote nodes contain
> static variables. I call MPI_Comm_spawn many times and these static
> variables don't seem to be able to retain their values between calls (on
> the master node) to MPI_Comm_spawn.
>
> Instead, its seems calling MPI_Comm_spawn resets the static variables.
> Does anyone have a suggestion as to how to keep simulate a 'static'
> variable on the slave nodes so that they retain their values between
> MPI_Comm_spawn calls?

So you're talking about a variable that is in the *spawned* process,
right?

The issue here is really outside the scope of MPI -- since your child
process is dying and then getting re-spawned, the entire process image is
gone (including static variables -- remember that static only applies for
the life of the process).

There's two typical solutions to this:

1. Write the values that you need to save to some kind of stable storage
(e.g., a disk file). Take care to avoid race conditions between instances
that will need to save their values, either by locking the stable storage
or having every instance write to different stable storage (i.e., there
will never be more than one process writing to a given storage at a time).

2. If there's only a few variables involved, you might want to send them
back to the master before the slave dies. Then, when the slave starts up
again, have the master send the last know values of those variables to the
slaves.

You can adapt either of these infinitely to match your specific needs, and
these are only two suggestions -- many more are probably possible.

Hope this helps!

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