]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Choose a more efficient algorithm. 16357/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 15 Dec 2023 08:03:37 +0000 (01:03 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 16 Dec 2023 15:44:09 +0000 (08:44 -0700)
include/deal.II/lac/sparse_matrix_tools.h

index 455a633e26b381d5877f493d7c3f3366d801a18f..4f49a41a18abe8a28a5fd4e28bacf4e97c699919 100644 (file)
@@ -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};
         }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.