From: bangerth Date: Fri, 24 May 2013 19:02:27 +0000 (+0000) Subject: Add locally_owned_elements() to all vector classes. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfdffca1f080de1eadc996a0e5f2764e55a860c3;p=dealii-svn.git Add locally_owned_elements() to all vector classes. git-svn-id: https://svn.dealii.org/trunk@29578 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 366a4d3618..fcb38a37b0 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -65,6 +65,15 @@ this function.
    +
  1. New: All vector classes now have a member function + locally_owned_elements that returns an index + set indicating which elements of this vector the current + processor owns. +
    + (Wolfgang Bangerth, 2013/05/24) +
  2. + +
  3. New: A new element FE_Q_iso_Q1 has been implemented that is defined by a subdivision of the element into smaller Q1 elements. An element of order @p p is similar to FE_Q of degree @p p with the same numbering of degrees of diff --git a/deal.II/include/deal.II/lac/block_vector_base.h b/deal.II/include/deal.II/lac/block_vector_base.h index 68b469c76f..a512e1aa44 100644 --- a/deal.II/include/deal.II/lac/block_vector_base.h +++ b/deal.II/include/deal.II/lac/block_vector_base.h @@ -846,6 +846,26 @@ public: */ unsigned int size () const; + /** + * Return an index set that describes which elements of this vector + * are owned by the current processor. Note that this index set does + * not include elements this vector may store locally as ghost + * elements but that are in fact owned by another processor. + * As a consequence, the index sets returned on different + * processors if this is a distributed vector will form disjoint + * sets that add up to the complete index set. + * Obviously, if a vector is created on only one processor, then + * the result would satisfy + * @code + * vec.locally_owned_elements() == complete_index_set (vec.size()) + * @endcode + * + * For block vectors, this function returns the union of the + * locally owned elements of the individual blocks, shifted by + * their respective index offsets. + */ + IndexSet locally_owned_elements () const; + /** * Return an iterator pointing to * the first element. @@ -1783,6 +1803,32 @@ BlockVectorBase::size () const +template +inline +IndexSet +BlockVectorBase::locally_owned_elements () const +{ + IndexSet is (size()); + + // copy index sets from blocks into the global one + for (unsigned int b=0; b inline unsigned int diff --git a/deal.II/include/deal.II/lac/parallel_vector.h b/deal.II/include/deal.II/lac/parallel_vector.h index aeef6b51f3..29d0b864b6 100644 --- a/deal.II/include/deal.II/lac/parallel_vector.h +++ b/deal.II/include/deal.II/lac/parallel_vector.h @@ -458,6 +458,22 @@ namespace parallel */ bool in_local_range (const types::global_dof_index global_index) const; + /** + * Return an index set that describes which elements of this vector + * are owned by the current processor. Note that this index set does + * not include elements this vector may store locally as ghost + * elements but that are in fact owned by another processor. + * As a consequence, the index sets returned on different + * processors if this is a distributed vector will form disjoint + * sets that add up to the complete index set. + * Obviously, if a vector is created on only one processor, then + * the result would satisfy + * @code + * vec.locally_owned_elements() == complete_index_set (vec.size()) + * @endcode + */ + IndexSet locally_owned_elements () const; + /** * Returns the number of ghost elements present on the vector. */ @@ -1429,6 +1445,20 @@ namespace parallel } + template + inline + IndexSet + Vector::locally_owned_elements() const + { + IndexSet is (size()); + + const std::pair x = local_range(); + is.add_range (x.first, x.second); + + return is; + } + + template inline diff --git a/deal.II/include/deal.II/lac/petsc_vector_base.h b/deal.II/include/deal.II/lac/petsc_vector_base.h index 49ad8674ad..4222be10e1 100644 --- a/deal.II/include/deal.II/lac/petsc_vector_base.h +++ b/deal.II/include/deal.II/lac/petsc_vector_base.h @@ -392,6 +392,22 @@ namespace PETScWrappers */ bool in_local_range (const unsigned int index) const; + /** + * Return an index set that describes which elements of this vector + * are owned by the current processor. Note that this index set does + * not include elements this vector may store locally as ghost + * elements but that are in fact owned by another processor. + * As a consequence, the index sets returned on different + * processors if this is a distributed vector will form disjoint + * sets that add up to the complete index set. + * Obviously, if a vector is created on only one processor, then + * the result would satisfy + * @code + * vec.locally_owned_elements() == complete_index_set (vec.size()) + * @endcode + */ + IndexSet locally_owned_elements () const; + /** * Return if the vector contains ghost * elements. @@ -1127,6 +1143,21 @@ namespace PETScWrappers (index < static_cast(end))); } + + inline + IndexSet + VectorBase::locally_owned_elements() const + { + IndexSet is (size()); + + // PETSc only allows for contiguous local ranges, so this is simple + const std::pair x = local_range(); + is.add_range (x.first, x.second); + return is; + } + + + inline bool VectorBase::has_ghost_elements() const diff --git a/deal.II/include/deal.II/lac/trilinos_vector_base.h b/deal.II/include/deal.II/lac/trilinos_vector_base.h index bd180641b9..05d5f24117 100644 --- a/deal.II/include/deal.II/lac/trilinos_vector_base.h +++ b/deal.II/include/deal.II/lac/trilinos_vector_base.h @@ -521,6 +521,22 @@ namespace TrilinosWrappers */ bool in_local_range (const unsigned int index) const; + /** + * Return an index set that describes which elements of this vector + * are owned by the current processor. Note that this index set does + * not include elements this vector may store locally as ghost + * elements but that are in fact owned by another processor. + * As a consequence, the index sets returned on different + * processors if this is a distributed vector will form disjoint + * sets that add up to the complete index set. + * Obviously, if a vector is created on only one processor, then + * the result would satisfy + * @code + * vec.locally_owned_elements() == complete_index_set (vec.size()) + * @endcode + */ + IndexSet locally_owned_elements () const; + /** * Return if the vector contains ghost * elements. This answer is true if there @@ -1226,6 +1242,23 @@ namespace TrilinosWrappers + inline + IndexSet + VectorBase::locally_owned_elements() const + { + IndexSet is (size()); + + // TODO: Trilinos does allow non-contiguous ranges for locally + // owned elements. if that is the case for the current + // vector, local_range() will throw an exception. Fix this. + const std::pair x = local_range(); + is.add_range (x.first, x.second); + + return is; + } + + + inline bool VectorBase::has_ghost_elements() const diff --git a/deal.II/include/deal.II/lac/vector.h b/deal.II/include/deal.II/lac/vector.h index 33f3a5ef47..6c7fe3e9ce 100644 --- a/deal.II/include/deal.II/lac/vector.h +++ b/deal.II/include/deal.II/lac/vector.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -600,6 +601,26 @@ public: */ bool in_local_range (const types::global_dof_index global_index) const; + /** + * Return an index set that describes which elements of this vector + * are owned by the current processor. Note that this index set does + * not include elements this vector may store locally as ghost + * elements but that are in fact owned by another processor. + * As a consequence, the index sets returned on different + * processors if this is a distributed vector will form disjoint + * sets that add up to the complete index set. + * Obviously, if a vector is created on only one processor, then + * the result would satisfy + * @code + * vec.locally_owned_elements() == complete_index_set (vec.size()) + * @endcode + * + * Since the current data type does not support parallel data storage + * across different processors, the returned index set is the + * complete index set. + */ + IndexSet locally_owned_elements () const; + /** * Return dimension of the vector. */ diff --git a/deal.II/include/deal.II/lac/vector.templates.h b/deal.II/include/deal.II/lac/vector.templates.h index 82437f140c..5cb3ba459a 100644 --- a/deal.II/include/deal.II/lac/vector.templates.h +++ b/deal.II/include/deal.II/lac/vector.templates.h @@ -1434,6 +1434,15 @@ void Vector::block_read (std::istream &in) +template +IndexSet +Vector::locally_owned_elements() const +{ + return complete_index_set(size()); +} + + + template std::size_t Vector::memory_consumption () const