From: Wolfgang Bangerth Date: Tue, 20 Mar 2018 23:06:31 +0000 (-0600) Subject: Fix quadratic behavior of SparsityPattern::copy_from(). X-Git-Tag: v9.0.0-rc1~287^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42292bec92eb5d436c40a7343ea0183429cfd9f8;p=dealii.git Fix quadratic behavior of SparsityPattern::copy_from(). --- diff --git a/source/lac/sparsity_pattern.cc b/source/lac/sparsity_pattern.cc index 57663b5ff2..4051dffa4c 100644 --- a/source/lac/sparsity_pattern.cc +++ b/source/lac/sparsity_pattern.cc @@ -545,13 +545,15 @@ void SparsityPattern::copy_from (const FullMatrix &matrix) // first init with the number of entries per row. if this matrix is square // then we also have to allocate memory for the diagonal entry, unless we // have already counted it + const bool matrix_is_square = (matrix.m() == matrix.n()); + std::vector entries_per_row (matrix.m(), 0); for (size_type row=0; row &matrix) reinit (matrix.m(), matrix.n(), entries_per_row); - // now set entries + // now set entries. if we enter entries row by row, then we'll get + // quadratic complexity in the number of entries per row. this is + // not usually a problem (we don't usually create dense matrices), + // but there are cases where it matters -- so we may as well be + // gentler and hand over a whole row of entries at a time + std::vector column_indices; + column_indices.reserve (*std::max_element (entries_per_row.begin(), + entries_per_row.end())); for (size_type row=0; row