Skip to content

Commit

Permalink
Merge pull request #16357 from bangerth/mpi-2
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Dec 16, 2023
2 parents a1e9d2a + fa2a1e6 commit 83805c5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/deal.II/lac/sparse_matrix_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ namespace SparseMatrixTools
{
T prefix = {};

// First obtain every process's prefix sum:
int ierr =
MPI_Exscan(&value,
&prefix,
Expand All @@ -166,7 +167,12 @@ namespace SparseMatrixTools
comm);
AssertThrowMPI(ierr);

T sum = Utilities::MPI::sum(value, comm);
// Then we also need the total sum. We could obtain it by
// calling Utilities::MPI::sum(), but it is cheaper if we
// broadcast it from the last process, which can compute it
// from its own prefix sum plus its own value.
T sum = Utilities::MPI::broadcast(
comm, prefix + value, Utilities::MPI::n_mpi_processes(comm) - 1);

return {prefix, sum};
}
Expand Down

0 comments on commit 83805c5

Please sign in to comment.