Can MPI sendbuf and recvbuf be the same thing?
Asked Answered
F

1

16

I'm adding together a load of array elements from each process:

double rho[1024];
//Some operation to calculate rho for each process;
MPI_Allreduce(rho,rho,1024,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);

Will having rho as both the sendbuf and recvbuf work?

Freaky answered 12/5, 2013 at 13:28 Comment(0)
S
26

Have you checked MPI_IN_PLACE? According to MPI_AllReduce man page and MPI doc it can be used to specify the same buffer for sendbuf and recvbuf as long as you are working inside the same group.

The call would look like:

MPI_Allreduce(MPI_IN_PLACE,rho,1024,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
Satyriasis answered 12/5, 2013 at 14:26 Comment(4)
+1 - In-place reductions can be a useful, and the above is the correct way to do it.Pyaemia
this is an elegant way to do this..his answer needs approval asap.Pastime
How about MPI_Reduce?Inflight
read the man page of MPI_Reduce, it's OK to use MPI_IN_PLACEBonneau

© 2022 - 2024 — McMap. All rights reserved.