Page MenuHomec4science

fft_plan_manager.cpp
No OneTemporary

File Metadata

Created
Sun, Apr 28, 08:12

fft_plan_manager.cpp

/**
* @file
* @section LICENSE
*
* Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne),
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "fft_plan_manager.hh"
#include "fftransform_fftw.hh"
#if defined(USE_CUFFT)
#include "fftransform_cufft.hh"
#endif
#include <list>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
FFTPlanManager::~FFTPlanManager() { clean(); }
/* -------------------------------------------------------------------------- */
namespace detail {
/// class purely for singleton instanciation
struct PublicFFTPlanManager : public FFTPlanManager {};
} // namespace detail
FFTPlanManager& FFTPlanManager::get() {
if (FFTPlanManager::singleton == nullptr)
FFTPlanManager::singleton =
std::make_unique<detail::PublicFFTPlanManager>();
return *FFTPlanManager::singleton;
}
/* -------------------------------------------------------------------------- */
void FFTPlanManager::clean() {
for (auto pair : plans) {
delete std::get<0>(pair.second);
delete std::get<1>(pair.second);
}
plans.clear();
}
/* -------------------------------------------------------------------------- */
template <>
void FFTPlanManager::destroyPlan<Real>(const Real* some) {
std::list<FFTMap::key_type> pairs;
for (auto & pair : plans) {
if (pair.first.first == some) { // C++14 use get<T>(pair.first)
delete std::get<0>(pair.second);
delete std::get<1>(pair.second);
pairs.push_back(pair.first);
}
}
for (auto & pair : pairs)
plans.erase(pair);
}
/* -------------------------------------------------------------------------- */
template <>
void FFTPlanManager::destroyPlan<Complex>(const Complex* some) {
std::list<FFTMap::key_type> pairs;
for (auto & pair : plans) {
if (pair.first.second == some) {
delete std::get<0>(pair.second);
delete std::get<1>(pair.second);
pairs.push_back(pair.first);
}
}
for (auto & pair : pairs)
plans.erase(pair);
}
/* -------------------------------------------------------------------------- */
std::unique_ptr<FFTPlanManager> FFTPlanManager::singleton = nullptr;
/* -------------------------------------------------------------------------- */
__END_TAMAAS__

Event Timeline