Hello:
The whole need for the static variable stemmed from the fact i had huge
amounts of data to send to each slave node for each time step in my
simulation and that MPI_Scatter was taking a long time to scatter these
variables to the slave in the first place.
Consequently, instead of scattering them everytime to the slave, I wanted to
only have to scatter them once, and then in subsequent spawns, send only
updates (which are smaller and faster to send) to the slaves...
so sending them back to the master would sorta defeat that purpose, and
being that i need to access these variables many many times each simulation,
writing to a storage space may be very slow.
If anyone has any other ideas, that would be great!
I have thought about putting an infinite loop in the slave/spawned routine
and using MPI_Barrier to synchronize data transfers between the master and
slave, but the fact that MATLAB/MEX is involved means the master routine
will have to exit completely and return control back to MATLAB, so I am not
sure the slave node can keep the MPI connection open with the master node if
the master node's MEX program exits completely to MATLAB.
Does anyone know if the MPI connection is kept alive if MPI_finalize is
never called?
Thanks,
Anne
-----Original Message-----
From: Jeff Squyres [mailto:jsquyres_at_[hidden]]
Sent: Wednesday, May 14, 2003 12:32 PM
To: General LAM/MPI mailing list
Subject: Re: LAM: static variables and MPI
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/
_______________________________________________
This list is archived at http://www.lam-mpi.org/MailArchives/lam/
|