From: Wolfgang Bangerth Date: Fri, 15 Dec 2023 08:03:37 +0000 (-0700) Subject: Choose a more efficient algorithm. X-Git-Tag: relicensing~241^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa2a1e6d1d609f5aa3d057a3e10d9e18a29bbfcc;p=dealii.git Choose a more efficient algorithm. --- diff --git a/include/deal.II/lac/sparse_matrix_tools.h b/include/deal.II/lac/sparse_matrix_tools.h index 455a633e26..4f49a41a18 100644 --- a/include/deal.II/lac/sparse_matrix_tools.h +++ b/include/deal.II/lac/sparse_matrix_tools.h @@ -157,6 +157,7 @@ namespace SparseMatrixTools { T prefix = {}; + // First obtain every process's prefix sum: int ierr = MPI_Exscan(&value, &prefix, @@ -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}; }