Commit db4eefd8 authored by Alexis SALZMAN's avatar Alexis SALZMAN

[xFEM] Adding optimized version of DeclareState/DeclareInterpolation

A DeclareInterpolation2 and DeclareState2 is added to xAlgorithm.h in
this commit. The idea is not to use them right away but instead to test
them in your context by switching names (remove the 2 and add
something to old version names). By context here I talk of compiler. For
those who use something else then GNU g++, those new versions have to be
validated because they use the following assertion not in the norm I
think:
The clear method of std::vector do not touch memory allocation.

Thus the glob and loc vectors use memory management a small number of
time (for the first set of key of each space for a priori one element
per space at most). Otherwise the insert is relying on already allocated
capacity.
If this assertion is not verified with other compiler something will have
to be added.

Besides this memory trick the main modification comes from valgrind
study. It shows that xFiniteElement destructor and setKeys count
respectively for 6.44% and 35.49% of 595 call to Declarinterpolation
with a total of 304 640 elements treated (512 per call).
KeysFor interfere in setKeys for 19.08%. As stated already by N.C.,
clearly those computation are too costly compared to the generality or
maintainability that they provides. The adopted solution was to remove
xFiniteElement usage in those functions. That may hurt ... Maybe the
loop on space, glob and loc ingredient may be encapsulate in something
.. or xFiniteElement may be cleaned.

For now those new versions are proof concept. Their performance shows up
more then 20% gain in some application with many declareXXX.

Note that new version pass test successfully.
parent 5859010b
...@@ -128,6 +128,45 @@ void DeclareInterpolation(const FIELD& fct, const CREA& value_creator, ITER it, ...@@ -128,6 +128,45 @@ void DeclareInterpolation(const FIELD& fct, const CREA& value_creator, ITER it,
return; return;
} }
template <class FIELD, class CREA, class ITER>
void DeclareInterpolation2(const FIELD& fct, const CREA& value_creator, ITER it, ITER end)
{
std::set<xValKey> remain;
auto double_manager = fct.getValueManager();
std::vector<xValKey> glob;
std::vector<xValKey> loc;
auto space_range = xtool::make_range(fct.begin(), fct.end());
for (; it != end; ++it)
{
AOMD::mEntity* e = *it;
glob.clear();
for (auto space : space_range)
{
loc.clear();
space->getKeys(e, &loc);
glob.insert(glob.end(), loc.begin(), loc.end());
}
for (auto& key : glob)
{
if (!double_manager->insert(key, value_creator)) remain.insert(key);
}
}
while (!remain.empty())
{
// see effective stl of Scott Meyers page 45 to understand the line below
for (std::set<xValKey>::iterator itk = remain.begin(); itk != remain.end();)
{
if (double_manager->insert(*itk, value_creator))
{
remain.erase(itk++);
}
else
++itk;
}
}
return;
}
// function deprecated // function deprecated
// use the classical "DeclareInterpolation" and "DeclareState" framework with a xValueCreatorLinkOnFront creator // use the classical "DeclareInterpolation" and "DeclareState" framework with a xValueCreatorLinkOnFront creator
/*template <class FIELD> /*template <class FIELD>
...@@ -1165,6 +1204,31 @@ void DeclareState(const FIELD& fct, const CREA& state_creator, ITER it, ITER end ...@@ -1165,6 +1204,31 @@ void DeclareState(const FIELD& fct, const CREA& state_creator, ITER it, ITER end
return; return;
} }
template <class FIELD, class CREA, class ITER>
void DeclareState2(const FIELD& fct, const CREA& state_creator, ITER it, ITER end)
{
auto double_manager = fct.getValueManager();
std::vector<xValKey> glob;
std::vector<xValKey> loc;
auto space_range = xtool::make_range(fct.begin(), fct.end());
for (; it != end; ++it)
{
AOMD::mEntity* e = *it;
glob.clear();
for (auto space : space_range)
{
loc.clear();
space->getKeys(e, &loc);
glob.insert(glob.end(), loc.begin(), loc.end());
}
typename FIELD::value_container_t vals;
double_manager->getValPtr(glob.begin(), glob.end(), vals);
std::transform(glob.begin(), glob.end(), vals.begin(), vals.begin(), state_creator);
}
return;
}
template <class FIELD, class ITER> template <class FIELD, class ITER>
void DeleteState(const FIELD& fct, ITER it, ITER end) void DeleteState(const FIELD& fct, ITER it, ITER end)
......
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