jsmith
jsmith

Reputation: 387

MPI Bcast and the number of processes

What is the semantics of Bcast when number of processes during this call is different than number of processes spawned at the beginning of a computation?

I need to handle a situation where user specifies too many processes that are necessary to perform computation. For example, user may decide to spawn 16 processes with mpirun, when I only need 12 to split the problem among processes. I'm handling this situation by comparing PID to 12 and ending a processes with MPI_Finalize, when PID is too high. I think this causes a deadlock in my application, because Bcast wants to send to all processes?

How to handle that? Should I just invoke Bcast in all processes, but just ignore the output in some?

Upvotes: 1

Views: 394

Answers (2)

Phil Miller
Phil Miller

Reputation: 38118

At program startup, every process should look at its own rank (from MPI_Comm_rank), the total number of processes (from MPI_Comm_size(MPI_COMM_WORLD)), and the number the computation actually needs. Have the ranks below the number you need create a new communicator that you'll actually use to do your work, and have all the remaining ranks just call MPI_Finalize.

Upvotes: 1

andreas
andreas

Reputation: 7415

Given that we receive, what could be considered, invalid input from the user, must we really continue program execution after realizing this? Isn't is better to display an error message to the user, saying that an invalid number of processes was requested, and also informing the user about the allowed interval (e.g. "16 processes was requested, however, the maximum number of processes are 12, the program will therefore now exit").

Otherwise, if this isn't a possible solution in your situation, chapter 6 "Groups, Contexts, Communicators, and Caching" and/or chapter 10 "Process Creation and Management" from the MPI 2.2 documentation might be of help. There is probably other, easier-to-read, documentation available somewhere else, but at least it's a start.

Upvotes: 2

Related Questions