From: Christoph Goering Date: Fri, 22 Dec 2017 22:01:27 +0000 (+0100) Subject: improved readability inside SparseMatrix::mmult(..) with DynamicSparsityPattern:... X-Git-Tag: v9.0.0-rc1~618^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fec52519d115a35694fe62d72587a93c20dabb1;p=dealii.git improved readability inside SparseMatrix::mmult(..) with DynamicSparsityPattern::compute_mmult_pattern(..) --- diff --git a/include/deal.II/lac/sparse_matrix.templates.h b/include/deal.II/lac/sparse_matrix.templates.h index f3969d8d7d..53cfc44520 100644 --- a/include/deal.II/lac/sparse_matrix.templates.h +++ b/include/deal.II/lac/sparse_matrix.templates.h @@ -1008,37 +1008,10 @@ SparseMatrix::mmult (SparseMatrix &C, C.clear(); sp_C.reinit (0,0,0); - // create a sparsity pattern for the matrix. we will go through all the - // rows in the matrix A, and for each column in a row we add the whole - // row of matrix B with that row number. This means that we will insert - // a lot of entries to each row, which is best handled by the - // DynamicSparsityPattern class. + // create a sparsity pattern for the matrix C. { - DynamicSparsityPattern dsp (m(), B.n()); - for (size_type i = 0; i < dsp.n_rows(); ++i) - { - const size_type *rows = &sp_A.colnums[sp_A.rowstart[i]]; - const size_type *const end_rows = - &sp_A.colnums[sp_A.rowstart[i+1]]; - for (; rows != end_rows; ++rows) - { - const size_type col = *rows; - size_type *new_cols = const_cast - (&sp_B.colnums[sp_B.rowstart[col]]); - size_type *end_new_cols = const_cast - (&sp_B.colnums[sp_B.rowstart[col+1]]); - - // if B has a diagonal, need to add that manually. this way, - // we maintain sortedness. - if (sp_B.n_rows() == sp_B.n_cols()) - { - ++new_cols; - dsp.add(i, col); - } - - dsp.add_entries (i, new_cols, end_new_cols, true); - } - } + DynamicSparsityPattern dsp ; + dsp.compute_mmult_pattern(sp_A,sp_B); sp_C.copy_from (dsp); }