From: Jan Philipp Thiele Date: Sat, 10 Feb 2024 12:44:58 +0000 (+0100) Subject: Add swap function to Tpetra vector X-Git-Tag: relicensing~54^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79bcfaf6f137b5ae88c50305be3f9e4cb07db485;p=dealii.git Add swap function to Tpetra vector --- diff --git a/include/deal.II/lac/trilinos_tpetra_vector.h b/include/deal.II/lac/trilinos_tpetra_vector.h index 5725daa0a9..d124158394 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.h @@ -366,6 +366,24 @@ namespace LinearAlgebra reinit(const Vector &V, const bool omit_zeroing_entries = false); + /** + * Swap the contents of this vector and the other vector @p v. One could do + * this operation with a temporary variable and copying over the data + * elements, but this function is significantly more efficient since it + * only swaps the pointers to the data of the two vectors and therefore + * does not need to allocate temporary storage and move data around. + * + * This function is analogous to the @p swap function of all C++ + * standard containers. Also, there is a global function + * swap(u,v) that simply calls u.swap(v), again in + * analogy to standard functions. + * + * This function is virtual in order to allow for derived classes to + * handle memory separately. + */ + virtual void + swap(Vector &v); + /** * Extract a range of elements all at once. */ @@ -923,6 +941,14 @@ namespace LinearAlgebra /* ------------------------- Inline functions ---------------------- */ + template + inline void + swap(Vector &u, Vector &v) + { + u.swap(v); + } + + template inline bool Vector::has_ghost_elements() const @@ -939,6 +965,12 @@ namespace LinearAlgebra return compressed; } + template + inline void + Vector::swap(Vector &v) + { + vector.swap(v.vector); + } template