From a0b0e89e09a7fcd94c374f35be568b9a2c05aeb8 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 05:44:13 -0700 Subject: [PATCH] Be more thoughtful about parallel grain sizes in UMFPACK interfaces. --- source/lac/sparse_direct.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/source/lac/sparse_direct.cc b/source/lac/sparse_direct.cc index 6807ce6433..7fb4254024 100644 --- a/source/lac/sparse_direct.cc +++ b/source/lac/sparse_direct.cc @@ -38,6 +38,25 @@ DEAL_II_NAMESPACE_OPEN #endif +namespace +{ + /** + * For a given matrix, compute a reasonable "grain size" when parallelizing + * some copying and sorting operations. The grain size is the minimal number + * of rows each thread should work on. We define it by assuming that + * dealing with 1000 matrix entries is a reasonable lower bound for parallel + * operations. + */ + template + unsigned int + parallel_grainsize(const SparseMatrixType &matrix) + { + const unsigned int avg_entries_per_row = + matrix.n_nonzero_elements() / matrix.m(); + return std::max(1000 / avg_entries_per_row, 1u); + } +} // namespace + SparseDirectUMFPACK::~SparseDirectUMFPACK() { @@ -146,7 +165,7 @@ SparseDirectUMFPACK::sort_arrays(const SparseMatrix &matrix) } } }, - /* grain size = */ 50); + parallel_grainsize(matrix)); } @@ -175,7 +194,7 @@ SparseDirectUMFPACK::sort_arrays(const SparseMatrixEZ &matrix) } } }, - /* grain size = */ 50); + parallel_grainsize(matrix)); } @@ -224,7 +243,7 @@ SparseDirectUMFPACK::sort_arrays(const BlockSparseMatrix &matrix) } } }, - /* grain size = */ 50); + parallel_grainsize(matrix)); } @@ -300,7 +319,7 @@ SparseDirectUMFPACK::factorize(const Matrix &matrix) Assert(index == Ap[row + 1], ExcInternalError()); } }, - /* grain size = */ 50); + parallel_grainsize(matrix)); // make sure that the elements in each row are sorted. we have to be more // careful for block sparse matrices, so ship this task out to a -- 2.39.5