From: kronbichler Date: Thu, 5 Nov 2009 19:53:22 +0000 (+0000) Subject: Fix distribute() function for distributed Trilinos vector. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff5ec4ebaf07212fc622f70d25906bfbd49548a2;p=dealii-svn.git Fix distribute() function for distributed Trilinos vector. git-svn-id: https://svn.dealii.org/trunk@20036 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/source/constraint_matrix.cc b/deal.II/lac/source/constraint_matrix.cc index c15362443e..132897abbf 100644 --- a/deal.II/lac/source/constraint_matrix.cc +++ b/deal.II/lac/source/constraint_matrix.cc @@ -1862,15 +1862,15 @@ template<> void ConstraintMatrix::distribute (TrilinosWrappers::MPI::Vector &vec) const { + typedef std::vector::const_iterator constraint_iterator; ConstraintLine index_comparison; - index_comparison.line = vec.local_range().first; - - std::vector::const_iterator next_constraint = + std::pair local_range = vec.local_range(); + index_comparison.line = local_range.first; + const constraint_iterator begin_my_constraints = std::lower_bound (lines.begin(),lines.end(),index_comparison); - index_comparison.line = vec.local_range().second; - - std::vector::const_iterator end_constraint + index_comparison.line = local_range.second; + const constraint_iterator end_my_constraints = std::lower_bound(lines.begin(),lines.end(),index_comparison); // Here we search all the indices that we @@ -1883,15 +1883,18 @@ ConstraintMatrix::distribute (TrilinosWrappers::MPI::Vector &vec) const { std::vector my_indices(vec.local_size()); unsigned int index2 = 0; - for(unsigned int i=vec.local_range().first;ientries.size(); ++i) - my_indices.push_back (next_constraint->entries[i].first); - } + for (constraint_iterator it = begin_my_constraints; + it != end_my_constraints; ++it) + for (unsigned int i=0; ientries.size(); ++i) + if ((it->entries[i].first < local_range.first) + || + (it->entries[i].first >= local_range.second)) + my_indices.push_back (it->entries[i].first); // sort and compress out duplicates std::sort(my_indices.begin(),my_indices.end()); @@ -1904,8 +1907,6 @@ ConstraintMatrix::distribute (TrilinosWrappers::MPI::Vector &vec) const } } - my_indices.resize(index2); - Epetra_Map map_exchange = Epetra_Map(-1,index2,(int*)&my_indices[0],0, vec.trilinos_vector().Comm()); @@ -1914,19 +1915,17 @@ ConstraintMatrix::distribute (TrilinosWrappers::MPI::Vector &vec) const // here we import the data vec_distribute->reinit(vec,false,true); - next_constraint = - std::lower_bound (lines.begin(),lines.end(),index_comparison); - - for (; next_constraint != end_constraint; ++next_constraint) + for (constraint_iterator it = begin_my_constraints; + it != end_my_constraints; ++it) { // fill entry in line // next_constraint.line by adding the // different contributions - double new_value = next_constraint->inhomogeneity; - for (unsigned int i=0; ientries.size(); ++i) - new_value += ((*vec_distribute)(next_constraint->entries[i].first) * - next_constraint->entries[i].second); - vec(next_constraint->line) = new_value; + double new_value = it->inhomogeneity; + for (unsigned int i=0; ientries.size(); ++i) + new_value += ((*vec_distribute)(it->entries[i].first) * + it->entries[i].second); + vec(it->line) = new_value; } }