Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer, es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Ein Anmelden über dieses erzeugt ein neues Konto. Das alte Konto ist über den Reiter "Standard" erreichbar. Die Administratoren

Dear Gitlab user, it is now possible to log in to our service using the ZIH login/LDAP. Logging in via this will create a new account. The old account can be accessed via the "Standard" tab. The administrators

Commit d7a4c589 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

move std::string in initialization, concurrent_cache improved

parent 5d80eba9
Pipeline #1309 passed with stage
in 19 minutes and 35 seconds
......@@ -26,21 +26,21 @@ namespace AMDiS
AdaptInfo::AdaptInfo(std::string name)
: name(name)
: name_(std::move(name))
{
// init();
Parameters::get(name + "->start time", startTime);
Parameters::get(name_ + "->start time", startTime);
time = startTime;
Parameters::get(name + "->timestep", timestep);
Parameters::get(name + "->end time", endTime);
Parameters::get(name + "->max iteration", maxSpaceIteration);
Parameters::get(name + "->max timestep iteration", maxTimestepIteration);
Parameters::get(name + "->max time iteration", maxTimeIteration);
Parameters::get(name + "->min timestep", minTimestep);
Parameters::get(name + "->max timestep", maxTimestep);
Parameters::get(name + "->number of timesteps", nTimesteps);
Parameters::get(name + "->time tolerance", globalTimeTolerance);
Parameters::get(name_ + "->timestep", timestep);
Parameters::get(name_ + "->end time", endTime);
Parameters::get(name_ + "->max iteration", maxSpaceIteration);
Parameters::get(name_ + "->max timestep iteration", maxTimestepIteration);
Parameters::get(name_ + "->max time iteration", maxTimeIteration);
Parameters::get(name_ + "->min timestep", minTimestep);
Parameters::get(name_ + "->max timestep", maxTimestep);
Parameters::get(name_ + "->number of timesteps", nTimesteps);
Parameters::get(name_ + "->time tolerance", globalTimeTolerance);
}
......@@ -73,7 +73,7 @@ namespace AMDiS
solverIterations = 0;
solverResidual = 0.0;
Parameters::get(name + "->timestep", timestep);
Parameters::get(name_ + "->timestep", timestep);
lastProcessedTimestep=timestep;
}
......
......@@ -712,13 +712,13 @@ namespace AMDiS
private:
ScalContent& getScalContent(Key key) const
{
auto result = scalContents.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(name + "[" + key + "]") );
auto result = scalContents.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(name_ + "[" + key + "]") );
return result.first->second;
}
protected:
/// Name.
std::string name;
std::string name_;
/// Current space iteration
int spaceIteration = -1;
......
......@@ -15,12 +15,12 @@ namespace AMDiS
AdaptInfo& adaptInfo,
ProblemTimeInterface& problemTime,
AdaptInfo& initialAdaptInfo)
: AdaptBase(name, &problemIteration, adaptInfo, &problemTime, &initialAdaptInfo)
: AdaptBase(std::move(name), &problemIteration, adaptInfo, &problemTime, &initialAdaptInfo)
{
Parameters::get(name + "->strategy", strategy_);
Parameters::get(name + "->time delta 1", timeDelta1_);
Parameters::get(name + "->time delta 2", timeDelta2_);
Parameters::get(name + "->break when stable", breakWhenStable_);
Parameters::get(name_ + "->strategy", strategy_);
Parameters::get(name_ + "->time delta 1", timeDelta1_);
Parameters::get(name_ + "->time delta 2", timeDelta2_);
Parameters::get(name_ + "->break when stable", breakWhenStable_);
fixedTimestep_ = (adaptInfo_.getMinTimestep() == adaptInfo_.getMaxTimestep());
}
......
......@@ -58,9 +58,6 @@ namespace AMDiS
*/
virtual void oneTimestep();
/// Initialisation of this AdaptInstationary object
void initialize(std::string aName);
/// Implements the explit time strategy. Used by \ref oneTimestep().
virtual void explicitTimeStrategy();
......
......@@ -17,7 +17,7 @@ namespace AMDiS
/// Stores cache global static, requires locking on write access.
template <class Container>
struct SharedPolicy;
struct StaticLockedPolicy;
/// \brief The class template ConcurrentCache describes an associative static container that allows the
......@@ -30,7 +30,7 @@ namespace AMDiS
* \tparam Data The type of the data stored in the cache. The behaviur is undefined if Data is not
* the same type as Container::mapped_type.
* \tparam Policy A policy class template implementing the method `get_or_init()`. Two implementations
* are provided: \ref ThreadLocalPolicy and \ref SharedPolicy. By default, if not
* are provided: \ref ThreadLocalPolicy and \ref StaticLockedPolicy. By default, if not
* Policy class template is specified, the `ThreadLocalPolicy` is used. \see ConcurrentCachePolicy
* \tparam Container The type of the underlying associative container to use to store the data. The
* container must satisfy the requirements of AssociativeContainer. The standard
......@@ -54,7 +54,7 @@ namespace AMDiS
* Provide a static cache and a `get_or_init()` static method that extracts the data from the cache if it exists or
* creates a new extry by using an initialization functor.
*
* Realizations of this template are \ref ThreadLocalPolicy and \ref SharedPolicy.
* Realizations of this template are \ref ThreadLocalPolicy and \ref StaticLockedPolicy.
*
* \tparam Container The Type of the associative container key->data to store the cached data.
**/
......@@ -72,20 +72,50 @@ namespace AMDiS
template <class F, class... Args>
static data_type const& get_or_init(key_type const& key, F&& f, Args&&... args)
{
return impl(std::is_default_constructible<data_type>{},
key, std::forward<F>(f), std::forward<Args>(args)...);
}
private:
// data_type is default_constructible
template <class F, class... Args>
static data_type const& impl(std::true_type, key_type const& key, F&& f, Args&&... args)
{
// Container to store the cached values
thread_local container_type cached_data;
data_type data = f(key, std::forward<Args>(args)...);
auto it = cached_data.emplace(key, std::move(data));
data_type empty;
auto it = cached_data.emplace(key, std::move(empty));
if (it.second) {
data_type data = f(key, std::forward<Args>(args)...);
it.first->second = std::move(data);
}
return it.first->second;
}
// data_type is not default_constructible
template <class F, class... Args>
static data_type const& impl(std::false_type, key_type const& key, F&& f, Args&&... args)
{
// Container to store the cached values
thread_local container_type cached_data;
auto it = cached_data.find(key);
if (it != cached_data.end())
return it->second;
else {
data_type data = f(key, std::forward<Args>(args)...);
auto it = cached_data.emplace(key, std::move(data));
return it.first->second;
}
}
};
// implementation of the Shared policy
template <class Container>
struct SharedPolicy
struct StaticLockedPolicy
{
using key_type = typename Container::key_type;
using data_type = typename Container::mapped_type;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment