mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-11-21 08:54:08 -06:00
threadmanager: remove unused typetag template parameter
and move implementation to a translation unit
This commit is contained in:
parent
3ee5eddf48
commit
e7a9c4cd21
@ -407,6 +407,7 @@ if(QuadMath_FOUND)
|
||||
co2injection_flash_ecfv
|
||||
co2injection_flash_vcfv)
|
||||
opm_add_test(${tapp}_quad
|
||||
LIBRARIES opmsimulators opmcommon
|
||||
EXE_NAME ${tapp}_quad
|
||||
SOURCES
|
||||
examples/${tapp}.cpp
|
||||
|
@ -61,6 +61,7 @@ list (APPEND MAIN_SOURCE_FILES
|
||||
opm/models/blackoil/blackoilmicpparams.cpp
|
||||
opm/models/blackoil/blackoilpolymerparams.cpp
|
||||
opm/models/blackoil/blackoilsolventparams.cpp
|
||||
opm/models/parallel/threadmanager.cpp
|
||||
opm/simulators/flow/ActionHandler.cpp
|
||||
opm/simulators/flow/Banners.cpp
|
||||
opm/simulators/flow/BlackoilModelParameters.cpp
|
||||
|
@ -219,7 +219,7 @@ struct ConstraintsContext<TypeTag, TTag::FvBaseDiscretization>
|
||||
*/
|
||||
template<class TypeTag>
|
||||
struct ThreadManager<TypeTag, TTag::FvBaseDiscretization>
|
||||
{ using type = ::Opm::ThreadManager<TypeTag>; };
|
||||
{ using type = ::Opm::ThreadManager; };
|
||||
|
||||
template<class TypeTag>
|
||||
struct UseLinearizationLock<TypeTag, TTag::FvBaseDiscretization>
|
||||
|
93
opm/models/parallel/threadmanager.cpp
Normal file
93
opm/models/parallel/threadmanager.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
// vi: set et ts=4 sw=4 sts=4:
|
||||
/*
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Consult the COPYING file in the top-level source directory of this
|
||||
module for the precise wording of the license and the list of
|
||||
copyright holders.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <opm/models/parallel/threadmanager.hpp>
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#include <opm/models/discretization/common/fvbaseparameters.hh>
|
||||
#include <opm/models/utils/parametersystem.hh>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
int ThreadManager::numThreads_ = 1;
|
||||
|
||||
void ThreadManager::registerParameters()
|
||||
{
|
||||
Parameters::Register<Parameters::ThreadsPerProcess>
|
||||
("The maximum number of threads to be instantiated per process "
|
||||
"('-1' means 'automatic')");
|
||||
}
|
||||
|
||||
void ThreadManager::init(bool queryCommandLineParameter)
|
||||
{
|
||||
if (queryCommandLineParameter) {
|
||||
numThreads_ = Parameters::Get<Parameters::ThreadsPerProcess>();
|
||||
|
||||
// some safety checks. This is pretty ugly macro-magic, but so what?
|
||||
#if !defined(_OPENMP)
|
||||
if (numThreads_ != 1 && numThreads_ != -1) {
|
||||
throw std::invalid_argument("OpenMP is not available. The only valid values for "
|
||||
"threads-per-process is 1 and -1 but it is "+std::to_string(numThreads_)+"!");
|
||||
}
|
||||
numThreads_ = 1;
|
||||
#elif !defined NDEBUG && defined DUNE_INTERFACECHECK
|
||||
if (numThreads_ != 1) {
|
||||
throw std::invalid_argument("You explicitly enabled Barton-Nackman interface checking in Dune. "
|
||||
"The Dune implementation of this is currently incompatible with "
|
||||
"thread parallelism!");
|
||||
}
|
||||
numThreads_ = 1;
|
||||
#else
|
||||
if (numThreads_ == 0) {
|
||||
throw std::invalid_argument("Zero threads per process are not possible: It must be at least 1, "
|
||||
"(or -1 for 'automatic')!");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _OPENMP
|
||||
// actually limit the number of threads
|
||||
if (numThreads_ > 0) {
|
||||
omp_set_num_threads(numThreads_);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _OPENMP
|
||||
// get the number of threads which are used in the end.
|
||||
numThreads_ = omp_get_max_threads();
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned ThreadManager::threadId()
|
||||
{
|
||||
#ifdef _OPENMP
|
||||
return static_cast<unsigned>(omp_get_thread_num());
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Opm
|
@ -27,22 +27,11 @@
|
||||
#ifndef OPM_THREAD_MANAGER_HPP
|
||||
#define OPM_THREAD_MANAGER_HPP
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#include <opm/models/discretization/common/fvbaseparameters.hh>
|
||||
#include <opm/models/utils/parametersystem.hh>
|
||||
#include <opm/models/utils/propertysystem.hh>
|
||||
|
||||
#include <dune/common/version.hh>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
/*!
|
||||
* \brief Simplifies multi-threaded capabilities.
|
||||
*/
|
||||
template <class TypeTag>
|
||||
class ThreadManager
|
||||
{
|
||||
public:
|
||||
@ -58,12 +47,7 @@ public:
|
||||
/*!
|
||||
* \brief Register all run-time parameters of the thread manager.
|
||||
*/
|
||||
static void registerParameters()
|
||||
{
|
||||
Parameters::Register<Parameters::ThreadsPerProcess>
|
||||
("The maximum number of threads to be instantiated per process "
|
||||
"('-1' means 'automatic')");
|
||||
}
|
||||
static void registerParameters();
|
||||
|
||||
/*!
|
||||
* \brief Initialize number of threads used thread manager.
|
||||
@ -74,43 +58,7 @@ public:
|
||||
* outside of this function (e.g. by OPM_NUM_THREADS or in the simulator by
|
||||
* the ThreadsPerProcess parameter).
|
||||
*/
|
||||
static void init(bool queryCommandLineParameter = true)
|
||||
{
|
||||
if (queryCommandLineParameter)
|
||||
{
|
||||
numThreads_ = Parameters::Get<Parameters::ThreadsPerProcess>();
|
||||
|
||||
// some safety checks. This is pretty ugly macro-magic, but so what?
|
||||
#if !defined(_OPENMP)
|
||||
if (numThreads_ != 1 && numThreads_ != -1)
|
||||
throw std::invalid_argument("OpenMP is not available. The only valid values for "
|
||||
"threads-per-process is 1 and -1 but it is "+std::to_string(numThreads_)+"!");
|
||||
numThreads_ = 1;
|
||||
#elif !defined NDEBUG && defined DUNE_INTERFACECHECK
|
||||
if (numThreads_ != 1)
|
||||
throw std::invalid_argument("You explicitly enabled Barton-Nackman interface checking in Dune. "
|
||||
"The Dune implementation of this is currently incompatible with "
|
||||
"thread parallelism!");
|
||||
numThreads_ = 1;
|
||||
#else
|
||||
|
||||
if (numThreads_ == 0)
|
||||
throw std::invalid_argument("Zero threads per process are not possible: It must be at least 1, "
|
||||
"(or -1 for 'automatic')!");
|
||||
#endif
|
||||
|
||||
#ifdef _OPENMP
|
||||
// actually limit the number of threads
|
||||
if (numThreads_ > 0)
|
||||
omp_set_num_threads(numThreads_);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _OPENMP
|
||||
// get the number of threads which are used in the end.
|
||||
numThreads_ = omp_get_max_threads();
|
||||
#endif
|
||||
}
|
||||
static void init(bool queryCommandLineParameter = true);
|
||||
|
||||
/*!
|
||||
* \brief Return the maximum number of threads of the current process.
|
||||
@ -121,22 +69,12 @@ public:
|
||||
/*!
|
||||
* \brief Return the index of the current OpenMP thread
|
||||
*/
|
||||
static unsigned threadId()
|
||||
{
|
||||
#ifdef _OPENMP
|
||||
return static_cast<unsigned>(omp_get_thread_num());
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
static unsigned threadId();
|
||||
|
||||
private:
|
||||
static int numThreads_;
|
||||
};
|
||||
|
||||
template <class TypeTag>
|
||||
int ThreadManager<TypeTag>::numThreads_ = 1;
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
#endif // OPM_THREAD_MANAGER_HPP
|
||||
|
@ -76,7 +76,7 @@ template <class TypeTag>
|
||||
static inline void registerAllParameters_(bool finalizeRegistration = true)
|
||||
{
|
||||
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
|
||||
using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||
using TM = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||
|
||||
Parameters::Register<Parameters::ParameterFile>
|
||||
("An .ini file which contains a set of run-time parameters");
|
||||
@ -84,7 +84,7 @@ static inline void registerAllParameters_(bool finalizeRegistration = true)
|
||||
("Print the values of the run-time parameters at the "
|
||||
"start of the simulation");
|
||||
|
||||
ThreadManager::registerParameters();
|
||||
TM::registerParameters();
|
||||
Simulator::registerParameters();
|
||||
|
||||
if (finalizeRegistration) {
|
||||
@ -279,7 +279,7 @@ static inline int start(int argc, char **argv, bool registerParams=true)
|
||||
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
|
||||
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
|
||||
using Problem = GetPropType<TypeTag, Properties::Problem>;
|
||||
using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||
using TM = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||
|
||||
// set the signal handlers to reset the TTY to a well defined state on unexpected
|
||||
// program aborts
|
||||
@ -304,7 +304,7 @@ static inline int start(int argc, char **argv, bool registerParams=true)
|
||||
if (paramStatus == 2)
|
||||
return 0;
|
||||
|
||||
ThreadManager::init();
|
||||
TM::init();
|
||||
|
||||
// initialize MPI, finalize is done automatically on exit
|
||||
#if HAVE_DUNE_FEM
|
||||
|
@ -38,6 +38,10 @@
|
||||
#include <dune/common/parallel/mpihelper.hh>
|
||||
#endif
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#include <charconv>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
@ -97,7 +101,7 @@ namespace Opm {
|
||||
("Developer option to see whether logging was on non-root processors. "
|
||||
"In that case it will be appended to the *.DBG or *.PRT files");
|
||||
|
||||
ThreadManager<TypeTag>::registerParameters();
|
||||
ThreadManager::registerParameters();
|
||||
Simulator::registerParameters();
|
||||
|
||||
// register the base parameters
|
||||
@ -305,8 +309,8 @@ namespace Opm {
|
||||
omp_set_num_threads(threads);
|
||||
#endif
|
||||
|
||||
using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||
ThreadManager::init(false);
|
||||
using TM = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||
TM::init(false);
|
||||
}
|
||||
|
||||
void mergeParallelLogFiles()
|
||||
|
@ -527,7 +527,7 @@ struct AquiferFixture {
|
||||
"test_RestartSerialization",
|
||||
"--ecl-deck-file-name=GLIFT1.DATA"
|
||||
};
|
||||
Opm::ThreadManager<TT>::registerParameters();
|
||||
Opm::ThreadManager::registerParameters();
|
||||
AdaptiveTimeStepping<TT>::registerParameters();
|
||||
BlackoilModelParameters<double>::registerParameters();
|
||||
Parameters::Register<Parameters::EnableTerminalOutput>("Do *NOT* use!");
|
||||
|
@ -232,7 +232,7 @@ struct EquilFixture {
|
||||
#endif
|
||||
using namespace Opm;
|
||||
FlowGenericVanguard::setCommunication(std::make_unique<Opm::Parallel::Communication>());
|
||||
Opm::ThreadManager<TypeTag>::registerParameters();
|
||||
Opm::ThreadManager::registerParameters();
|
||||
BlackoilModelParameters<double>::registerParameters();
|
||||
AdaptiveTimeStepping<TypeTag>::registerParameters();
|
||||
Parameters::Register<Parameters::EnableTerminalOutput>("Dummy added for the well model to compile.");
|
||||
|
@ -116,7 +116,7 @@ BOOST_FIXTURE_TEST_CASE(WithOutputDir, Fixture)
|
||||
|
||||
Opm::Parameters::reset();
|
||||
|
||||
Opm::ThreadManager<int>::registerParameters();
|
||||
Opm::ThreadManager::registerParameters();
|
||||
Opm::Main main(3, const_cast<char**>(no_param), false);
|
||||
|
||||
BOOST_CHECK_EQUAL(main.justInitialize(), EXIT_SUCCESS);
|
||||
@ -154,7 +154,7 @@ BOOST_FIXTURE_TEST_CASE(NoOutputDir, Fixture)
|
||||
const char* no_param[] = {"test_outputdir", input_file_path.c_str(), nullptr};
|
||||
|
||||
Opm::Parameters::reset();
|
||||
Opm::ThreadManager<int>::registerParameters();
|
||||
Opm::ThreadManager::registerParameters();
|
||||
|
||||
Opm::Main main(2, const_cast<char**>(no_param), false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user