Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
amdis
amdis-core
Commits
d7a4c589
Commit
d7a4c589
authored
Oct 16, 2018
by
Praetorius, Simon
Browse files
move std::string in initialization, concurrent_cache improved
parent
5d80eba9
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/amdis/AdaptInfo.cpp
View file @
d7a4c589
...
...
@@ -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
;
}
...
...
src/amdis/AdaptInfo.hpp
View file @
d7a4c589
...
...
@@ -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
;
...
...
src/amdis/AdaptInstationary.cpp
View file @
d7a4c589
...
...
@@ -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
());
}
...
...
src/amdis/AdaptInstationary.hpp
View file @
d7a4c589
...
...
@@ -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
();
...
...
src/amdis/utility/ConcurrentCache.hpp
View file @
d7a4c589
...
...
@@ -17,7 +17,7 @@ namespace AMDiS
/// Stores cache global static, requires locking on write access.
template
<
class
Container
>
struct
S
har
edPolicy
;
struct
S
taticLock
edPolicy
;
/// \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 S
har
edPolicy. By default, if not
* are provided: \ref ThreadLocalPolicy and \ref S
taticLock
edPolicy. 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 S
har
edPolicy.
* Realizations of this template are \ref ThreadLocalPolicy and \ref S
taticLock
edPolicy.
*
* \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
S
har
edPolicy
struct
S
taticLock
edPolicy
{
using
key_type
=
typename
Container
::
key_type
;
using
data_type
=
typename
Container
::
mapped_type
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment