From 4bed2c036d1cb9d4d6c8843d121b55cdf3245752 Mon Sep 17 00:00:00 2001 From: Katharina Kormann Date: Sat, 13 Jun 2009 13:34:37 +0000 Subject: [PATCH] implement distribute function for parallel Trilinos vector git-svn-id: https://svn.dealii.org/trunk@18935 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/constraint_matrix.h | 14 +++- deal.II/lac/source/constraint_matrix.cc | 89 +++++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/deal.II/lac/include/lac/constraint_matrix.h b/deal.II/lac/include/lac/constraint_matrix.h index 221704a33b..64113296a6 100644 --- a/deal.II/lac/include/lac/constraint_matrix.h +++ b/deal.II/lac/include/lac/constraint_matrix.h @@ -10,8 +10,8 @@ // further information on this license. // //--------------------------------------------------------------------------- -#ifndef __deal2__dof_constraints_h -#define __deal2__dof_constraints_h +#ifndef __deal2__constraint_matrix_h +#define __deal2__constraint_matrix_h #include @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -1513,6 +1515,14 @@ class ConstraintMatrix : public Subscriptor const bool keep_constrained_entries, const Table<2,bool> &dof_mask, internal::bool2type) const; + +#ifdef DEAL_II_USE_TRILINOS + /** + * This vector is used to import data + * within the distribute function. + */ + mutable TrilinosWrappers::MPI::Vector vec_distribute; +#endif }; diff --git a/deal.II/lac/source/constraint_matrix.cc b/deal.II/lac/source/constraint_matrix.cc index 7f6ea40e29..25b93e962c 100644 --- a/deal.II/lac/source/constraint_matrix.cc +++ b/deal.II/lac/source/constraint_matrix.cc @@ -740,6 +740,13 @@ void ConstraintMatrix::clear () std::vector tmp; constraint_line_exists.swap (tmp); } + +#ifdef DEAL_II_USE_TRILINOS + { + // reset distribute vector + vec_distribute.clear(); + } +#endif sorted = false; } @@ -1852,6 +1859,88 @@ void ConstraintMatrix::condense (BlockCompressedSimpleSparsityPattern &sparsity) +#ifdef DEAL_II_USE_TRILINOS + + // this is a specialization for a + // parallel (non-block) Trilinos + // vector. The basic idea is to just work + // on the local range of the vector. But + // we need access to values that the + // local nodes are constrained to. +template<> +void +ConstraintMatrix::distribute (TrilinosWrappers::MPI::Vector &vec) const +{ + Assert (sorted == true, ExcMatrixNotClosed()); + ConstraintLine index_comparison; + index_comparison.line = vec.local_range().first; + + std::vector::const_iterator next_constraint = + std::lower_bound (lines.begin(),lines.end(),index_comparison); + + index_comparison.line = vec.local_range().second; + + std::vector::const_iterator end_constraint + = std::lower_bound(lines.begin(),lines.end(),index_comparison); + + // Here we search all the indices that we + // need to have read-access to - the + // local nodes and all the nodes that the + // constraints indicate. Do this only at + // the first call and provide the class + // with a vector for further use. + if (vec_distribute.size()!=vec.size()) + { + 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); + } + + // sort and compress out duplicates + std::sort(my_indices.begin(),my_indices.end()); + index2 = 1; + for(unsigned int index1=1;index1inhomogeneity; + 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; + } +} + +#endif + + unsigned int ConstraintMatrix::n_constraints () const { return lines.size(); -- 2.39.5