Skip to content

Commit

Permalink
Use MPI_IN_PLACE (AMReX-Codes#3428)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Jul 19, 2023
1 parent 10b6cb2 commit fc32f3e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Src/Base/AMReX_ParallelReduce.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ namespace detail {
inline void Reduce (ReduceOp op, T* v, int cnt, int root, MPI_Comm comm)
{
auto mpi_op = mpi_ops[static_cast<int>(op)]; // NOLINT
Vector<T> tmp(v, v+cnt);
if (root == -1) {
// TODO: add BL_COMM_PROFILE commands
MPI_Allreduce(tmp.data(), v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
MPI_Allreduce(MPI_IN_PLACE, v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
mpi_op, comm);
} else {
// TODO: add BL_COMM_PROFILE commands
MPI_Reduce(tmp.data(), v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
const auto* sendbuf = (ParallelDescriptor::MyProc(comm) == root) ?
(void const*)(MPI_IN_PLACE) : (void const*) v;
MPI_Reduce(sendbuf, v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
mpi_op, root, comm);
}
}
Expand Down

0 comments on commit fc32f3e

Please sign in to comment.