From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 12:44:13 +0000 (-0700) Subject: Be more thoughtful about parallel grain sizes in UMFPACK interfaces. X-Git-Tag: v9.4.0-rc1~646^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0b0e89e09a7fcd94c374f35be568b9a2c05aeb8;p=dealii.git Be more thoughtful about parallel grain sizes in UMFPACK interfaces. --- 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