From: bangerth Date: Thu, 8 May 2008 22:13:26 +0000 (+0000) Subject: Fix creation of a sparse matrix with Trilinos. Also make it more efficient. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6303582ee4761c808729b660aefd9ccb2a101d1f;p=dealii-svn.git Fix creation of a sparse matrix with Trilinos. Also make it more efficient. git-svn-id: https://svn.dealii.org/trunk@16062 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-33/step-33.cc b/deal.II/examples/step-33/step-33.cc index eeabd9f615..4196402799 100644 --- a/deal.II/examples/step-33/step-33.cc +++ b/deal.II/examples/step-33/step-33.cc @@ -1223,37 +1223,28 @@ void ConsLaw::setup_system () Map = new Epetra_Map(dof_handler.n_dofs(), 0, *Comm); // Epetra can build a more efficient matrix if - // one knows ahead of time the maxiumum number of - // columns in any row entry. We traverse the sparsity - // to discover this. - unsigned int cur_row = 0; - unsigned int cur_col = 0; - unsigned int max_df = -1; - for (SparsityPattern::iterator s_i = sparsity_pattern.begin(); - s_i != sparsity_pattern.end(); s_i++) { - if (s_i->row() != cur_row) { - cur_col = 0; - cur_row = s_i->row(); - } - cur_col++; - if (cur_col >= max_df) max_df = cur_col; - } - - if (cur_col >= max_df) max_df = cur_col; - std::cout << "max_df:" << max_df << std::endl; - - // Now we build the matrix, using the constructor - // that optimizes with the max_df variable. + // one knows ahead of time the maximum number of + // columns in any row entry + std::vector row_lengths (dof_handler.n_dofs()); + for (unsigned int i=0; i vals(max_df, 0); - std::vector row_indices(max_df); + const unsigned int max_nonzero_entries = *std::max_element (row_lengths.begin(), + row_lengths.end()); + std::vector vals(max_nonzero_entries, 0); + std::vector row_indices(max_nonzero_entries); - cur_row = 0; - cur_col = 0; + unsigned int cur_row = 0; + unsigned int cur_col = 0; for (SparsityPattern::iterator s_i = sparsity_pattern.begin(); s_i != sparsity_pattern.end(); s_i++) { if (s_i->row() != cur_row) {