Sarah
Sarah

Reputation: 133

How to select a master processor randomly in MPI programming?

I need to select one processor from my Comm to do some works ( I don`t want other processors do the work ). Since I split my Comm to the groups, I cannot always pick one specific rank ( for example 0) as my master. I need to choose it from my current comm. Any suggestion?

Thank you.

Upvotes: 0

Views: 316

Answers (2)

Zulan
Zulan

Reputation: 22670

The accepted answer by suszterpatt is correct and this is what you should normally do. Nevertheless, I'd like to address the title of the question of randomly selecting a master process. To do that

  1. Every rank in the communicator generates a random number
  2. Distribute the random number and the rank number using MPI_Allreduce with MPI_MAXLOC.
  3. Now every rank in the communicator can use the rank as a master.

Upvotes: 0

suszterpatt
suszterpatt

Reputation: 8273

The rank of a process is always relative to a communicator. After you split your processes, you can just take process 0 in the new communicator to perform the work you want.

Upvotes: 3

Related Questions