Discussion:
Broadcast from a root whose task number isn't known a priori?
(too old to reply)
Mark
2011-03-31 20:30:55 UTC
Permalink
Hello,

Is there any way to broadcast data from one process to all other
processes without knowing a priori who the root of the broadcast will
be? From what I've read, that doesn't seem possible with MPI_Bcast
since all processes must specify the "root" when they call MPI_Bcast,
but if they don't know a priori who the "root" process is then there
is no way for every MPI_Bcast to specify the root. Unless I'm missing
something obvious, which is always a probable possibility...

To give an example, what I'm trying to do is essentially this: Each
process has a collection of integers. One (and only one, by design)
process has in its collection an integer equal to 0. The process that
possesses the integer 0 must then broadcast an array of data to all of
the other processes. However, the process that contains the integer 0
can change during the course of the run. What is the best way to
achieve this in MPI?

Thanks for your help,

Mark
Michael Hofmann
2011-04-01 06:57:13 UTC
Permalink
Post by Mark
Hello,
Is there any way to broadcast data from one process to all other
processes without knowing a priori who the root of the broadcast will
be? From what I've read, that doesn't seem possible with MPI_Bcast
since all processes must specify the "root" when they call MPI_Bcast,
but if they don't know a priori who the "root" process is then there
is no way for every MPI_Bcast to specify the root. Unless I'm missing
something obvious, which is always a probable possibility...
No, that is not possible with MPI_Bcast.
Post by Mark
To give an example, what I'm trying to do is essentially this: Each
process has a collection of integers. One (and only one, by design)
process has in its collection an integer equal to 0. The process that
possesses the integer 0 must then broadcast an array of data to all of
the other processes. However, the process that contains the integer 0
can change during the course of the run. What is the best way to
achieve this in MPI?
If you want to use MPI_Bcast (which is a good idea), all processes have
to know the rank of the root processes. One way to achieve this is as
follows: Use an MPI_Allreduce with MPI_SUM where all non-root processes
contribute value "0" and the root processes contributes its rank value.
The sum of all these values is the rank of the root process and this
result of MPI_Allreduce is available to all processes.


Michael
Mark
2011-04-01 16:59:14 UTC
Permalink
Post by Michael Hofmann
Post by Mark
Hello,
Is there any way to broadcast data from one process to all other
processes without knowing a priori who the root of the broadcast will
be?  From what I've read, that doesn't seem possible with MPI_Bcast
since all processes must specify the "root" when they call MPI_Bcast,
but if they don't know a priori who the "root" process is then there
is no way for every MPI_Bcast to specify the root.  Unless I'm missing
something obvious, which is always a probable possibility...
No, that is not possible with MPI_Bcast.
Post by Mark
To give an example, what I'm trying to do is essentially this:  Each
process has a collection of integers.  One (and only one, by design)
process has in its collection an integer equal to 0.  The process that
possesses the integer 0 must then broadcast an array of data to all of
the other processes.  However, the process that contains the integer 0
can change during the course of the run.  What is the best way to
achieve this in MPI?
If you want to use MPI_Bcast (which is a good idea), all processes have
to know the rank of the root processes. One way to achieve this is as
follows: Use an MPI_Allreduce with MPI_SUM where all non-root processes
contribute value "0" and the root processes contributes its rank value.
The sum of all these values is the rank of the root process and this
result of MPI_Allreduce is available to all processes.
That's a clever solution, thank you very much for the tip!

Best,
Mark

Loading...