From: Matthias Maier Date: Sat, 2 May 2015 08:10:57 +0000 (+0200) Subject: Do not clear vectors in move operators/constructors for distributed data structures X-Git-Tag: v8.3.0-rc1~203^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b527ce7a8fb9627ff7771053789b380091b3df5e;p=dealii.git Do not clear vectors in move operators/constructors for distributed data structures --- diff --git a/include/deal.II/lac/petsc_parallel_block_vector.h b/include/deal.II/lac/petsc_parallel_block_vector.h index 73e1b79a04..5294689154 100644 --- a/include/deal.II/lac/petsc_parallel_block_vector.h +++ b/include/deal.II/lac/petsc_parallel_block_vector.h @@ -113,12 +113,7 @@ namespace PETScWrappers * @note This operator is only available if deal.II is configured with * C++11 support. */ - BlockVector (BlockVector &&v) - { - swap(v); - // be nice and reset v to zero - v.reinit(0, v.get_mpi_communicator(), 0, 0, false); - } + BlockVector (BlockVector &&v); #endif /** @@ -168,20 +163,12 @@ namespace PETScWrappers #ifdef DEAL_II_WITH_CXX11 /** * Move the given vector. This operator replaces the present vector with - * @p v by efficiently swapping the internal data structures. @p v is - * left empty. + * @p v by efficiently swapping the internal data structures. * * @note This operator is only available if deal.II is configured with * C++11 support. */ - BlockVector &operator= (BlockVector &&v) - { - swap(v); - // be nice and reset v to zero - v.reinit(0, v.get_mpi_communicator(), 0, 0, false); - - return *this; - } + BlockVector &operator= (BlockVector &&v); #endif /** @@ -371,6 +358,14 @@ namespace PETScWrappers this->components[i] = v.components[i]; } +#ifdef DEAL_II_WITH_CXX11 + inline + BlockVector::BlockVector (BlockVector &&v) + { + swap(v); + } +#endif + inline BlockVector::BlockVector (const std::vector ¶llel_partitioning, const MPI_Comm &communicator) @@ -414,6 +409,16 @@ namespace PETScWrappers return *this; } +#ifdef DEAL_II_WITH_CXX11 + inline + BlockVector & + BlockVector::operator= (BlockVector &&v) + { + swap(v); + return *this; + } +#endif + inline BlockVector::~BlockVector () {} diff --git a/include/deal.II/lac/petsc_parallel_vector.h b/include/deal.II/lac/petsc_parallel_vector.h index 2166061143..a34a0376d6 100644 --- a/include/deal.II/lac/petsc_parallel_vector.h +++ b/include/deal.II/lac/petsc_parallel_vector.h @@ -197,12 +197,7 @@ namespace PETScWrappers * @note This operator is only available if deal.II is configured with * C++11 support. */ - Vector (Vector &&v) - { - swap(v); - // be nice and reset v to zero - v.reinit(v.communicator, 0, 0, false); - } + Vector (Vector &&v); #endif /** @@ -291,20 +286,12 @@ namespace PETScWrappers #ifdef DEAL_II_WITH_CXX11 /** * Move the given vector. This operator replaces the present vector with - * @p v by efficiently swapping the internal data structures. @p v is - * left empty. + * @p v by efficiently swapping the internal data structures. * * @note This operator is only available if deal.II is configured with * C++11 support. */ - Vector &operator= (Vector &&v) - { - swap(v); - // be nice and reset v to zero - v.reinit(v.communicator, 0, 0, false); - - return *this; - } + Vector &operator= (Vector &&v); #endif /** @@ -565,6 +552,17 @@ namespace PETScWrappers +#ifdef DEAL_II_WITH_CXX11 + inline + Vector & Vector::operator= (Vector &&v) + { + swap(v); + return *this; + } +#endif + + + template inline Vector & diff --git a/include/deal.II/lac/trilinos_parallel_block_vector.h b/include/deal.II/lac/trilinos_parallel_block_vector.h index 3deb3b709d..79b5ce176c 100644 --- a/include/deal.II/lac/trilinos_parallel_block_vector.h +++ b/include/deal.II/lac/trilinos_parallel_block_vector.h @@ -138,11 +138,7 @@ namespace TrilinosWrappers * @note This constructor is only available if deal.II is configured with * C++11 support. */ - BlockVector (BlockVector &&v) - { - swap(v); - v.reinit (0); - } + BlockVector (BlockVector &&v); #endif /** @@ -171,20 +167,12 @@ namespace TrilinosWrappers #ifdef DEAL_II_WITH_CXX11 /** * Move the given vector. This operator replaces the present vector with - * @p v by efficiently swapping the internal data structures. @p v is - * left empty. + * @p v by efficiently swapping the internal data structures. * * @note This operator is only available if deal.II is configured with * C++11 support. */ - BlockVector &operator= (BlockVector &&v) - { - swap(v); - // be nice and reset v to zero - v.reinit (0); - - return *this; - } + BlockVector &operator= (BlockVector &&v); #endif /** @@ -412,6 +400,16 @@ namespace TrilinosWrappers +#ifdef DEAL_II_WITH_CXX11 + inline + BlockVector::BlockVector (BlockVector &&v) + { + swap(v); + } +#endif + + + inline bool BlockVector::is_compressed () const diff --git a/include/deal.II/lac/trilinos_vector.h b/include/deal.II/lac/trilinos_vector.h index c561202d75..542473c189 100644 --- a/include/deal.II/lac/trilinos_vector.h +++ b/include/deal.II/lac/trilinos_vector.h @@ -294,12 +294,7 @@ namespace TrilinosWrappers * @note This constructor is only available if deal.II is configured with * C++11 support. */ - Vector (Vector &&v) - { - swap(v); - // be nice and reset v to zero - v.clear(); - } + Vector (Vector &&v); #endif /** @@ -354,20 +349,12 @@ namespace TrilinosWrappers #ifdef DEAL_II_WITH_CXX11 /** * Move the given vector. This operator replaces the present vector with - * @p v by efficiently swapping the internal data structures. @p v is - * left empty. + * @p v by efficiently swapping the internal data structures. * * @note This operator is only available if deal.II is configured with * C++11 support. */ - Vector &operator= (Vector &&v) - { - swap(v); - // be nice and reset v to zero - v.clear(); - - return *this; - } + Vector &operator= (Vector &&v); #endif /** diff --git a/source/lac/petsc_parallel_vector.cc b/source/lac/petsc_parallel_vector.cc index 1bae4a9045..898b98e23c 100644 --- a/source/lac/petsc_parallel_vector.cc +++ b/source/lac/petsc_parallel_vector.cc @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2004 - 2014 by the deal.II authors +// Copyright (C) 2004 - 2015 by the deal.II authors // // This file is part of the deal.II library. // @@ -43,6 +43,15 @@ namespace PETScWrappers +#ifdef DEAL_II_WITH_CXX11 + Vector::Vector (Vector &&v) + { + swap(v); + } +#endif + + + Vector::Vector (const MPI_Comm &communicator, const size_type n, const size_type local_size) diff --git a/source/lac/trilinos_block_vector.cc b/source/lac/trilinos_block_vector.cc index d7714f8401..cb7e3d59fe 100644 --- a/source/lac/trilinos_block_vector.cc +++ b/source/lac/trilinos_block_vector.cc @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2008 - 2014 by the deal.II authors +// Copyright (C) 2008 - 2015 by the deal.II authors // // This file is part of the deal.II library. // @@ -76,6 +76,17 @@ namespace TrilinosWrappers +#ifdef DEAL_II_WITH_CXX11 + BlockVector & + BlockVector::operator= (BlockVector &&v) + { + swap(v); + return *this; + } +#endif + + + BlockVector & BlockVector::operator = (const ::dealii::TrilinosWrappers::BlockVector &v) { diff --git a/source/lac/trilinos_vector.cc b/source/lac/trilinos_vector.cc index eadd00c906..a4301fbeb2 100644 --- a/source/lac/trilinos_vector.cc +++ b/source/lac/trilinos_vector.cc @@ -125,6 +125,15 @@ namespace TrilinosWrappers +#ifdef DEAL_II_WITH_CXX11 + Vector::Vector (Vector &&v) + { + swap(v); + } +#endif + + + Vector::Vector (const Epetra_Map &input_map, const VectorBase &v) : @@ -421,6 +430,16 @@ namespace TrilinosWrappers +#ifdef DEAL_II_WITH_CXX11 + Vector & Vector::operator= (Vector &&v) + { + swap(v); + return *this; + } +#endif + + + Vector & Vector::operator = (const TrilinosWrappers::Vector &v) { diff --git a/tests/trilinos/vector_move_operations.cc b/tests/trilinos/vector_move_operations.cc index 1a57fbaae1..1558c2d1c5 100644 --- a/tests/trilinos/vector_move_operations.cc +++ b/tests/trilinos/vector_move_operations.cc @@ -56,6 +56,7 @@ int main (int argc, char **argv) PRINTME("copy assignemnt", v); PRINTME("old object", u); + v.clear(); v = std::move(u); PRINTME("move assignemnt", v); deallog << "old object size: " << u.size() << std::endl; @@ -83,6 +84,7 @@ int main (int argc, char **argv) PRINTBLOCK("copy assignemnt", v); PRINTBLOCK("old object", u); + v.reinit(0); v = std::move(u); PRINTBLOCK("move assignemnt", v); deallog << "old object size: " << u.n_blocks() << std::endl;