Reputation: 18
In MPI, is it possible to immediately throw out received data without allocating a buffer to hold it? I'm using MPI_Allgather to collect data from several processes, but at some point, one or more processes have no useful data to send.
My original solution was to let the useless process finish. However, if a task terminates without calling MPI_Allgather, the rest end up in deadlock, because MPI_Allgather blocks. In order to overcome this problem I keep all the processes around until the end, but send junk data that is never used.
The useful processes keep some of the received data, but the useless processes don't. I tried passing a null pointer for the recbuf like so:
MPI_Allgather(&sendbuf, 1, MPI_INT, 0, 1, MPI_INT, MPI_COMM_WORLD);
but it didn't work. Is the anything I can do to avoid receiving, or at least storing the useless data?
Upvotes: 0
Views: 342
Reputation: 4671
Collectives are by definition collective, which means every process in the communicator must call them. If you need to perform a collective call over a subset of a communicator, you have to make a new communicator, as already suggested.
You could also look at MPI_Allgatherv
and see if it's a good fit for your application. With this collective you can specify how much data each process will send. However, every process in the communicator must still call MPI_Allgatherv
, even those that send no data. In addition to this requirement, all processes must know how much data each process is contributing.
Finally, MPI 3 will most likely include sparse collective operations which do exactly what you wish. But for now a new communicator is probably the best approach.
Upvotes: 1
Reputation: 8273
You could create a new group for the useful processes and gather over that group instead of MPI_COMM_WORLD
.
Upvotes: 2