From: kronbichler Date: Fri, 28 Nov 2008 10:24:51 +0000 (+0000) Subject: Made the collective add and set functions a bit faster. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af5f45a1978e5d86a6c6ac4b1657934cca4d5f3f;p=dealii-svn.git Made the collective add and set functions a bit faster. git-svn-id: https://svn.dealii.org/trunk@17767 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/dofs/dof_constraints.templates.h b/deal.II/deal.II/include/dofs/dof_constraints.templates.h index 22f1ba11b0..befc30a16b 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.templates.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.templates.h @@ -709,8 +709,11 @@ distribute_local_to_global (const FullMatrix &local_matrix, // order to obtain a sufficient size // for the scratch array. n_max_entries_per_row += n_local_dofs; - column_indices.resize(n_max_entries_per_row); - column_values.resize(n_max_entries_per_row); + if (column_indices.size() < n_max_entries_per_row) + { + column_indices.resize(n_max_entries_per_row); + column_values.resize(n_max_entries_per_row); + } // now distribute entries row by row for (unsigned int i=0; i::set (const unsigned int row, const bool elide_zero_values) { // Resize scratch arrays - column_indices.resize (this->n_block_cols()); - column_values.resize (this->n_block_cols()); - counter_within_block.resize (this->n_block_cols()); - - // Resize sub-arrays to n_cols. This is a - // bit wasteful, but we resize only a few - // times (then the maximum row length - // won't increase that much any more). - for (unsigned int i=0; in_block_cols(); ++i) + if (column_indices.size() < this->n_block_cols()) + { + column_indices.resize (this->n_block_cols()); + column_values.resize (this->n_block_cols()); + counter_within_block.resize (this->n_block_cols()); + } + + // Resize sub-arrays to n_cols. This + // is a bit wasteful, but we resize + // only a few times (then the maximum + // row length won't increase that + // much any more). At least we know + // that all arrays are going to be of + // the same size, so we can check + // whether the size of one is large + // enough before actually going + // through all of them. + if (column_indices[0].size() < n_cols) { - column_indices[i].resize(n_cols); - column_values[i].resize(n_cols); - counter_within_block[i] = 0; + for (unsigned int i=0; in_block_cols(); ++i) + { + column_indices[i].resize(n_cols); + column_values[i].resize(n_cols); + } } - // Go through the column indices to find - // out which portions of the values - // should be written into which block - // matrix. We need to restore all the - // data, since we can't be sure that the - // data of one block is stored - // contiguously (in fact, it will be - // intermixed when the data comes from an - // element matrix). + // Reset the number of added elements + // in each block to zero. + for (unsigned int i=0; in_block_cols(); ++i) + counter_within_block[i] = 0; + + // Go through the column indices to + // find out which portions of the + // values should be set in which + // block of the matrix. We need to + // touch all the data, since we can't + // be sure that the data of one block + // is stored contiguously (in fact, + // indices will be intermixed when it + // comes from an element matrix). for (unsigned int j=0; j::add (const unsigned int row, // TODO: Look over this to find out // whether we can do that more // efficiently. + // Resize scratch arrays - column_indices.resize (this->n_block_cols()); - column_values.resize (this->n_block_cols()); - counter_within_block.resize (this->n_block_cols()); - - // Resize sub-arrays to n_cols. This is a - // bit wasteful, but we resize only a few - // times (then the maximum row length - // won't increase that much any more). - for (unsigned int i=0; in_block_cols(); ++i) + if (column_indices.size() < this->n_block_cols()) { - column_indices[i].resize(n_cols); - column_values[i].resize(n_cols); - counter_within_block[i] = 0; + column_indices.resize (this->n_block_cols()); + column_values.resize (this->n_block_cols()); + counter_within_block.resize (this->n_block_cols()); } - // Go through the column indices to find - // out which portions of the values - // should be written into which block - // matrix. We need to restore all the - // data, since we can't be sure that the - // data of one block is stored - // contiguously (in fact, it will be - // intermixed when the data comes from an - // element matrix). + // Resize sub-arrays to n_cols. This + // is a bit wasteful, but we resize + // only a few times (then the maximum + // row length won't increase that + // much any more). At least we know + // that all arrays are going to be of + // the same size, so we can check + // whether the size of one is large + // enough before actually going + // through all of them. + if (column_indices[0].size() < n_cols) + { + for (unsigned int i=0; in_block_cols(); ++i) + { + column_indices[i].resize(n_cols); + column_values[i].resize(n_cols); + } + } + + // Reset the number of added elements + // in each block to zero. + for (unsigned int i=0; in_block_cols(); ++i) + counter_within_block[i] = 0; + + // Go through the column indices to + // find out which portions of the + // values should be written into + // which block of the matrix. We need + // to touch all the data, since we + // can't be sure that the data of one + // block is stored contiguously (in + // fact, data will be intermixed when + // it comes from an element matrix). for (unsigned int j=0; j::add (const unsigned int row, unsigned int n_columns = 0; - global_indices.resize(n_cols); - column_values.resize(n_cols); + if (global_indices.size() < n_cols) + { + global_indices.resize(n_cols); + column_values.resize(n_cols); + } // First, search all the indices to find // out which values we actually need to diff --git a/deal.II/lac/include/lac/trilinos_sparse_matrix.h b/deal.II/lac/include/lac/trilinos_sparse_matrix.h index 5ac56828d5..2d25253f11 100755 --- a/deal.II/lac/include/lac/trilinos_sparse_matrix.h +++ b/deal.II/lac/include/lac/trilinos_sparse_matrix.h @@ -2170,8 +2170,11 @@ namespace TrilinosWrappers // Otherwise, extract nonzero values in // each row and get the respective // indices. - column_indices.resize(n_cols); - column_values.resize(n_cols); + if (column_indices.size() < n_cols) + { + column_indices.resize(n_cols); + column_values.resize(n_cols); + } n_columns = 0; for (unsigned int j=0; j