From 5188e8ef7ca46665c8b018c94901c3132dcb3073 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 31 Mar 2020 19:38:45 -0400 Subject: [PATCH] Remove SwappableVector --- .../incompatibilities/20200331DanielArndt | 3 + include/deal.II/lac/swappable_vector.h | 231 --------------- .../deal.II/lac/swappable_vector.templates.h | 272 ------------------ source/lac/CMakeLists.txt | 1 - source/lac/swappable_vector.cc | 24 -- 5 files changed, 3 insertions(+), 528 deletions(-) create mode 100644 doc/news/changes/incompatibilities/20200331DanielArndt delete mode 100644 include/deal.II/lac/swappable_vector.h delete mode 100644 include/deal.II/lac/swappable_vector.templates.h delete mode 100644 source/lac/swappable_vector.cc diff --git a/doc/news/changes/incompatibilities/20200331DanielArndt b/doc/news/changes/incompatibilities/20200331DanielArndt new file mode 100644 index 0000000000..3860957d17 --- /dev/null +++ b/doc/news/changes/incompatibilities/20200331DanielArndt @@ -0,0 +1,3 @@ +Removed: The deprecated class SwappableVector has been removed. +
+(Daniel Arndt, 2020/03/31) diff --git a/include/deal.II/lac/swappable_vector.h b/include/deal.II/lac/swappable_vector.h deleted file mode 100644 index 6c45f3f7a5..0000000000 --- a/include/deal.II/lac/swappable_vector.h +++ /dev/null @@ -1,231 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2000 - 2018 by the deal.II authors -// -// This file is part of the deal.II library. -// -// The deal.II library is free software; you can use it, redistribute -// it, and/or modify it under the terms of the GNU Lesser General -// Public License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// The full text of the license can be found in the file LICENSE.md at -// the top level directory of deal.II. -// -// --------------------------------------------------------------------- - -#ifndef dealii_swappable_vector_h -# define dealii_swappable_vector_h - - -# include - -# include - -# include - -# include - -DEAL_II_NAMESPACE_OPEN - -/*! @addtogroup Vectors - *@{ - */ - -/** - * This class is a wrapper to the @p Vector class which allows to swap out the - * data to a file and reload it later on. It handles the management of the - * name of the file where the data is to be stored temporarily and removes the - * file is necessary at the end of the lifetime of the vector. - * - * There are functions to swap the data to a file, and to reload it. There is - * also a function @p alert that can be used to signal to an object of this - * class that the data will be needed shortly, so the object can initiate that - * the data be loaded already. While in non-multithreading mode, this function - * has no effect since @p reload has to be called afterwards anyway. On the - * other hand, in multithreading mode, the data is preloaded in the background - * using a thread on its own, and may already be available at the time when @p - * reload is called. If it is not available, @p reload waits until the - * detached thread has loaded the data. - * - * @note Instantiations for this template are provided for @ and - * @; others can be generated in application programs (see the - * section on - * @ref Instantiations - * in the manual). - * - * @deprecated The usage of this class is deprecated. - * - * @author Wolfgang Bangerth, 1999, 2000 - */ -template -class DEAL_II_DEPRECATED SwappableVector : public Vector -{ -public: - /** - * Constructor. Does nothing apart from calling the constructor of the - * underlying class. - */ - SwappableVector(); - - /** - * Copy constructor. Copies the data if @p v contains some, but does not do - * so if @p v is empty or has its data swapped out. In the latter case, warn - * about that. In particular do not take over ownership of any files that @p - * v might own. - */ - SwappableVector(const SwappableVector &v); - - /** - * Destructor. If this class still owns a file to which temporary data was - * stored, then it is deleted. - */ - virtual ~SwappableVector() override; - - /** - * Copy operator. Do mostly the same as the copy constructor does; if - * necessary, delete temporary files owned by this object at first. - */ - SwappableVector & - operator=(const SwappableVector &); - - /** - * Swap out the data of this vector to the file of which the name is given. - * It is assumed that the file can be overwritten if it exists, and - * ownership of this file is assumed by this object. The file is deleted - * either upon calling @p kill_file, or on destruction of this object. - * - * The content of the vector is cleared and it size is reset to zero. - * - * If this object owns another file, for example when @p swap_out but no @p - * kill_file has previously been called, then that is deleted first. - */ - void - swap_out(const std::string &filename); - - /** - * Reload the data of this vector from the file to which it has been stored - * previously using @p swap_out. Since the file is not deleted after - * reloading, you can call @p reload multiple times, in between you may do - * everything with the vector, including changing its size. - * - * This function resets the size of the vector to the number of elements - * there were upon calling @p swap_out before. - */ - void - reload(); - - /** - * Calling this function can be used to alert this vector that it will need - * to reload its data soon. It has no effect if the data of the vector is - * already present, and it has no effect in single-thread mode as well, but - * in multithread mode, it spawns another thread that reads the data in - * parallel to the usual execution of the program, such that when @p reload - * is called, the data may eventually be available already. It might - * therefore be worthwhile to call this function some time in advance, if - * you know that the data will be needed, and loading takes some time, for - * instance if the file to which the data was written is not in a local tmp - * directory. - * - * Calling this function multiple times before calling @p reload is allowed - * and has no effect for subsequent calls. Calling this function while the - * data is still or already in memory is allowed and has no effect. - */ - void - alert(); - - - /** - * Remove the file to which the data has been stored the last time. After - * this, the object does not own any file any more, so of course you can't - * call @p reload again. - * - * If this object does not own a file, for example since @p swap_out was not - * called, or because @p kill_file has been called previously, then this - * function does nothing. - * - * This throws a ExcIO exception if, for any reason, deleting the file - * failed. - */ - void - kill_file(); - - /** - * Return the name of the file to which the data was stored the last time - * you called @p swap_out. If @p swap_out was not called, or if in between - * @p kill_file was called, then the filename is an empty string. - */ - const std::string & - get_filename() const; - - /** - * Determine an estimate for the memory consumption (in bytes) of this - * object. - */ - std::size_t - memory_consumption() const; - - /** - * @addtogroup Exceptions - * @{ - */ - /** - * Exception. - */ - DeclException0(ExcSizeZero); - /** - * Exception. - */ - DeclException0(ExcSizeNonzero); - /** - * Exception. - */ - DeclException1(ExcInvalidFilename, - std::string, - << "The filename <" << arg1 << "> is not a valid one here."); - /** - * Exception. - */ - DeclException0(ExcInvalidCopyOperation); - //@} -private: - /** - * Name of the file to which data was swapped out. If no data is presently - * swapped out (i.e. before calling @p swap_out and after @p kill_file), the - * string is empty, indicating no ownership of files. - */ - std::string filename; - - /** - * If in multithread mode, then the @p alert function has functionality, but - * needs to coordinate with the @p reload function. This is done through the - * following lock. - * - * If not in MT mode, then the class used here is empty, and we can as well - * get away with it. - */ - std::mutex lock; - - /** - * Flag by which the @p alert function signifies that the data has been - * preloaded already. This flag is always @p false in non-MT mode. - */ - bool data_is_preloaded; - - /** - * Internal function that actually reloads the vector. Called from @p reload - * and @p alert. - * - * The parameter specifies whether the function shall set @p - * data_is_preloaded or not. The calling functions can't sometimes do this - * themselves, since they call this function detached, so this function has - * to signal success itself if this is required. - */ - void - reload_vector(const bool set_flag); -}; - -/*@}*/ -DEAL_II_NAMESPACE_CLOSE - -#endif // dealii_swappable_vector_h -/*--------------------------- swappable_vector.h --------------------------*/ diff --git a/include/deal.II/lac/swappable_vector.templates.h b/include/deal.II/lac/swappable_vector.templates.h deleted file mode 100644 index 2402e90bc1..0000000000 --- a/include/deal.II/lac/swappable_vector.templates.h +++ /dev/null @@ -1,272 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2000 - 2019 by the deal.II authors -// -// This file is part of the deal.II library. -// -// The deal.II library is free software; you can use it, redistribute -// it, and/or modify it under the terms of the GNU Lesser General -// Public License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// The full text of the license can be found in the file LICENSE.md at -// the top level directory of deal.II. -// -// --------------------------------------------------------------------- - -#ifndef dealii_swappable_vector_templates_h -#define dealii_swappable_vector_templates_h - - -#include - -#include - -#include - -#include - -DEAL_II_NAMESPACE_OPEN - - -template -SwappableVector::SwappableVector() - : data_is_preloaded(false) -{} - - - -template -SwappableVector::SwappableVector(const SwappableVector &v) - : Vector(v) - , filename() - , data_is_preloaded(false) -{ - Assert(v.filename.empty(), ExcInvalidCopyOperation()); -} - - - -template -SwappableVector::~SwappableVector() -{ - // if the vector was stored in a - // file previously, and that has - // not been deleted in the - // meantime, then we kill that file - // first, before killing the vector - // itself - - if (!filename.empty()) - { - try - { - kill_file(); - } - catch (...) - {} - } -} - - - -template -SwappableVector & -SwappableVector::operator=(const SwappableVector &v) -{ - // if necessary, first delete data - if (!filename.empty()) - kill_file(); - - // if in MT mode, block all other - // operations. if not in MT mode, - // this is a no-op - std::lock_guard lock(this->lock); - - Vector::operator=(v); - data_is_preloaded = false; - - return *this; -} - - - -template -void -SwappableVector::swap_out(const std::string &name) -{ - // if the vector was stored in - // another file previously, and - // that has not been deleted in the - // meantime, then we kill that file - // first - if (!filename.empty()) - kill_file(); - - filename = name; - - Assert(this->size() != 0, ExcSizeZero()); - - // if in MT mode, block all other - // operations. if not in MT mode, - // this is a no-op - std::lock_guard lock(this->lock); - - // check that we have not called - // @p alert without the respective - // @p reload function - Assert(data_is_preloaded == false, ExcInternalError()); - - std::ofstream tmp_out(filename.c_str()); - this->block_write(tmp_out); - tmp_out.close(); - - this->reinit(0); -} - - - -template -void -SwappableVector::reload() -{ - // if in MT mode: synchronize with - // possibly existing @p alert - // calls. if not in MT mode, this - // is a no-op - lock.lock(); - - // if data was already preloaded, - // then there is no more need to - // load it - if (data_is_preloaded == false) - // reload data. note that this - // function also releases the - // lock - reload_vector(false); - else - { - // clear flag since no more - // needed - data_is_preloaded = false; - - // release lock. the lock is - // also released in the other - // branch of the if-clause - lock.unlock(); - } -} - - - -template -void -SwappableVector::alert() -{ -#ifndef DEAL_II_WITH_THREADS - // note: this function does nothing - // in non-MT mode - return; -#else - - // synchronize with possible other - // invocations of this function and - // other functions in this class - lock.lock(); - - // calling this function multiple - // times does no harm: - if ((data_is_preloaded == true) || - // calling this function while the - // vector is active does no harm - // either - (this->size() != 0)) - lock.unlock(); - else - // data has not been preloaded so - // far, so go on! For this, start - // a detached thread - Threads::new_thread(&SwappableVector::reload_vector, *this, true); - // note that reload_vector also - // releases the lock -#endif -} - - - -template -void -SwappableVector::reload_vector(const bool set_flag) -{ - (void)set_flag; - - Assert(!filename.empty(), ExcInvalidFilename(filename)); - Assert(this->size() == 0, ExcSizeNonzero()); - - std::ifstream tmp_in(filename.c_str()); - this->block_read(tmp_in); - tmp_in.close(); - -#ifdef DEAL_II_WITH_THREADS - // release the lock that was acquired by the calling functions - - // set the flag if so required - if (set_flag) - data_is_preloaded = true; - lock.unlock(); -#endif -} - - - -template -void -SwappableVector::kill_file() -{ - // if in MT mode, wait for other - // operations to finish first - // (there should be none, but who - // knows). if not in MT mode, - // this is a no-op - std::lock_guard lock(this->lock); - - // this is too bad: someone - // requested the vector in advance, - // but never got to fetch it. this - // is most probably an error, not? - Assert(data_is_preloaded == false, ExcInternalError()); - - if (!filename.empty()) - { - int status = std::remove(filename.c_str()); - (void)status; - AssertThrow(status == 0, ExcIO()); - - filename = ""; - }; -} - - - -template -const std::string & -SwappableVector::get_filename() const -{ - return filename; -} - - - -template -std::size_t -SwappableVector::memory_consumption() const -{ - return (MemoryConsumption::memory_consumption(filename) + sizeof(lock) + - MemoryConsumption::memory_consumption(data_is_preloaded) + - Vector::memory_consumption()); -} - - - -DEAL_II_NAMESPACE_CLOSE - -#endif // dealii_swappable_vector_templates_h diff --git a/source/lac/CMakeLists.txt b/source/lac/CMakeLists.txt index 7afbc26a98..420a5100d1 100644 --- a/source/lac/CMakeLists.txt +++ b/source/lac/CMakeLists.txt @@ -45,7 +45,6 @@ SET(_unity_include_src sparse_vanka.cc sparsity_pattern.cc sparsity_tools.cc - swappable_vector.cc vector.cc vector_memory.cc ) diff --git a/source/lac/swappable_vector.cc b/source/lac/swappable_vector.cc deleted file mode 100644 index 9041629356..0000000000 --- a/source/lac/swappable_vector.cc +++ /dev/null @@ -1,24 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2000 - 2014 by the deal.II authors -// -// This file is part of the deal.II library. -// -// The deal.II library is free software; you can use it, redistribute -// it, and/or modify it under the terms of the GNU Lesser General -// Public License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// The full text of the license can be found in the file LICENSE.md at -// the top level directory of deal.II. -// -// --------------------------------------------------------------------- - -#include - -DEAL_II_NAMESPACE_OPEN - -// explicit instantiations -template class SwappableVector; -template class SwappableVector; - -DEAL_II_NAMESPACE_CLOSE -- 2.39.5