0
if(mpi_rank.eq.master)then
 call mpi_bcast(a, 1, mpi_integer, mpi_rank, mpi_comm_world, ierr)
endif

The above will not work since in fact not all processors are calling mpi_bcast. We can only use send receive in this case?

In this case, only the master processor knows he is the master advisor. Others do not know. I have tried many approaches. This seems difficult for me. Only the master knows he is the master processor and he is gonna share some value with all the other processors.

Taitai
  • 584
  • 2
  • 7
  • 18
  • 1
    Can you please clarify the actual problem you want to solve? As it's currently written, it’s hard to tell exactly what you're asking. – Zulan May 08 '16 at 20:32
  • This isn't how you invoke `MPI_Bcast()`. **Every** task has to call `MPI_Bcast()`, not just the task with the data you want to be sent, _e.g._, http://stackoverflow.com/a/7867789/463827 . In this case, you would write just a single line, `call MPI_Bcast(a, 1, MPI_INTEGER, master, MPI_COMM_WORLD, err)`, with no if statement. – Jonathan Dursi May 08 '16 at 22:13
  • or use a different communicator, e.g. `MPI_COMM_SELF`? – Ed Smith May 09 '16 at 12:49
  • 1
    What about you call a `MPI_Allreduce()` with all processes passing either -1 if they aren't master, or its rank if master? You would use `MPI_MAX` as operator and then all processes would know who is the master and could call correctly `MPI_Bcast()` with this information.... – Gilles May 09 '16 at 14:11
  • @Gilles, Good idea!! I think I can also use `mpi_sum`, if they are not master, they can pass `0`, right? Thanks! – Taitai May 09 '16 at 14:33

0 Answers0