Commit 2620c115 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Some performance issues, part III. ElementObjectDatabase requires now onl 10% of the memory.

parent 2d6d2384
...@@ -23,6 +23,14 @@ namespace AMDiS { ...@@ -23,6 +23,14 @@ namespace AMDiS {
macroElementRankMap = &rankMap; macroElementRankMap = &rankMap;
levelData = &ld; levelData = &ld;
// === Reset temporary data ===
tmpVertexElements.clear();
tmpEdgeElements.clear();
tmpFaceElements.clear();
// === Fills macro element data structures. === // === Fills macro element data structures. ===
TraverseStack stack; TraverseStack stack;
...@@ -42,6 +50,26 @@ namespace AMDiS { ...@@ -42,6 +50,26 @@ namespace AMDiS {
elInfo = stack.traverseNext(elInfo); elInfo = stack.traverseNext(elInfo);
} }
// === Move temporary data to original one ===
for (map<DegreeOfFreedom, vector<ElementObjectData> >::iterator it = tmpVertexElements.begin();
it != tmpVertexElements.end(); ++it)
vertexElements[it->first] = it->second;
tmpVertexElements.clear();
for (map<DofEdge, vector<ElementObjectData> >::iterator it = tmpEdgeElements.begin();
it != tmpEdgeElements.end(); ++it)
edgeElements[it->first] = it->second;
tmpEdgeElements.clear();
for (map<DofFace, vector<ElementObjectData> >::iterator it = tmpFaceElements.begin();
it != tmpFaceElements.end(); ++it)
faceElements[it->first] = it->second;
tmpFaceElements.clear();
// Handle periodic boudaries // Handle periodic boudaries
createPeriodicData(); createPeriodicData();
...@@ -186,7 +214,7 @@ namespace AMDiS { ...@@ -186,7 +214,7 @@ namespace AMDiS {
int elIndex = el->getIndex(); int elIndex = el->getIndex();
ElementObjectData elObj(elIndex, ith); ElementObjectData elObj(elIndex, ith);
vertexElements[vertex].push_back(elObj); tmpVertexElements[vertex].push_back(elObj);
vertexLocalMap[elObj] = vertex; vertexLocalMap[elObj] = vertex;
} }
...@@ -199,7 +227,7 @@ namespace AMDiS { ...@@ -199,7 +227,7 @@ namespace AMDiS {
int elIndex = el->getIndex(); int elIndex = el->getIndex();
ElementObjectData elObj(elIndex, ith); ElementObjectData elObj(elIndex, ith);
edgeElements[edge].push_back(elObj); tmpEdgeElements[edge].push_back(elObj);
edgeLocalMap[elObj] = edge; edgeLocalMap[elObj] = edge;
} }
...@@ -210,7 +238,7 @@ namespace AMDiS { ...@@ -210,7 +238,7 @@ namespace AMDiS {
int elIndex = el->getIndex(); int elIndex = el->getIndex();
ElementObjectData elObj(elIndex, ith); ElementObjectData elObj(elIndex, ith);
faceElements[face].push_back(elObj); tmpFaceElements[face].push_back(elObj);
faceLocalMap[elObj] = face; faceLocalMap[elObj] = face;
} }
...@@ -469,7 +497,7 @@ namespace AMDiS { ...@@ -469,7 +497,7 @@ namespace AMDiS {
TEST_EXIT(macroElementRankMap)("Should not happen!\n"); TEST_EXIT(macroElementRankMap)("Should not happen!\n");
vertexInRank.clear(); vertexInRank.clear();
for (map<DegreeOfFreedom, vector<ElementObjectData> >::iterator it = vertexElements.begin(); for (flat_map<DegreeOfFreedom, vector<ElementObjectData> >::iterator it = vertexElements.begin();
it != vertexElements.end(); ++it) { it != vertexElements.end(); ++it) {
for (vector<ElementObjectData>::iterator it2 = it->second.begin(); for (vector<ElementObjectData>::iterator it2 = it->second.begin();
it2 != it->second.end(); ++it2) { it2 != it->second.end(); ++it2) {
...@@ -480,7 +508,7 @@ namespace AMDiS { ...@@ -480,7 +508,7 @@ namespace AMDiS {
} }
edgeInRank.clear(); edgeInRank.clear();
for (map<DofEdge, vector<ElementObjectData> >::iterator it = edgeElements.begin(); for (flat_map<DofEdge, vector<ElementObjectData> >::iterator it = edgeElements.begin();
it != edgeElements.end(); ++it) { it != edgeElements.end(); ++it) {
for (vector<ElementObjectData>::iterator it2 = it->second.begin(); for (vector<ElementObjectData>::iterator it2 = it->second.begin();
it2 != it->second.end(); ++it2) { it2 != it->second.end(); ++it2) {
...@@ -491,7 +519,7 @@ namespace AMDiS { ...@@ -491,7 +519,7 @@ namespace AMDiS {
} }
faceInRank.clear(); faceInRank.clear();
for (map<DofFace, vector<ElementObjectData> >::iterator it = faceElements.begin(); for (flat_map<DofFace, vector<ElementObjectData> >::iterator it = faceElements.begin();
it != faceElements.end(); ++it) { it != faceElements.end(); ++it) {
for (vector<ElementObjectData>::iterator it2 = it->second.begin(); for (vector<ElementObjectData>::iterator it2 = it->second.begin();
it2 != it->second.end(); ++it2) { it2 != it->second.end(); ++it2) {
...@@ -547,7 +575,7 @@ namespace AMDiS { ...@@ -547,7 +575,7 @@ namespace AMDiS {
// === First, create reverse modes for all "directly" neighbouring elements. === // === First, create reverse modes for all "directly" neighbouring elements. ===
for (map<DofEdge, vector<ElementObjectData> >::iterator edgeIt = edgeElements.begin(); for (flat_map<DofEdge, vector<ElementObjectData> >::iterator edgeIt = edgeElements.begin();
edgeIt != edgeElements.end(); ++edgeIt) { edgeIt != edgeElements.end(); ++edgeIt) {
vector<ElementObjectData>& els = edgeIt->second; vector<ElementObjectData>& els = edgeIt->second;
...@@ -572,7 +600,7 @@ namespace AMDiS { ...@@ -572,7 +600,7 @@ namespace AMDiS {
} }
} }
for (map<DofFace, vector<ElementObjectData> >::iterator faceIt = faceElements.begin(); for (flat_map<DofFace, vector<ElementObjectData> >::iterator faceIt = faceElements.begin();
faceIt != faceElements.end(); ++faceIt) { faceIt != faceElements.end(); ++faceIt) {
vector<ElementObjectData>& els = faceIt->second; vector<ElementObjectData>& els = faceIt->second;
...@@ -771,7 +799,7 @@ namespace AMDiS { ...@@ -771,7 +799,7 @@ namespace AMDiS {
int nSize = vertexElements.size(); int nSize = vertexElements.size();
SerUtil::serialize(out, nSize); SerUtil::serialize(out, nSize);
for (map<DegreeOfFreedom, vector<ElementObjectData> >::iterator it = vertexElements.begin(); for (flat_map<DegreeOfFreedom, vector<ElementObjectData> >::iterator it = vertexElements.begin();
it != vertexElements.end(); ++it) { it != vertexElements.end(); ++it) {
SerUtil::serialize(out, it->first); SerUtil::serialize(out, it->first);
serialize(out, it->second); serialize(out, it->second);
...@@ -779,7 +807,7 @@ namespace AMDiS { ...@@ -779,7 +807,7 @@ namespace AMDiS {
nSize = edgeElements.size(); nSize = edgeElements.size();
SerUtil::serialize(out, nSize); SerUtil::serialize(out, nSize);
for (map<DofEdge, vector<ElementObjectData> >::iterator it = edgeElements.begin(); for (flat_map<DofEdge, vector<ElementObjectData> >::iterator it = edgeElements.begin();
it != edgeElements.end(); ++it) { it != edgeElements.end(); ++it) {
SerUtil::serialize(out, it->first); SerUtil::serialize(out, it->first);
serialize(out, it->second); serialize(out, it->second);
...@@ -787,7 +815,7 @@ namespace AMDiS { ...@@ -787,7 +815,7 @@ namespace AMDiS {
nSize = faceElements.size(); nSize = faceElements.size();
SerUtil::serialize(out, nSize); SerUtil::serialize(out, nSize);
for (map<DofFace, vector<ElementObjectData> >::iterator it = faceElements.begin(); for (flat_map<DofFace, vector<ElementObjectData> >::iterator it = faceElements.begin();
it != faceElements.end(); ++it) { it != faceElements.end(); ++it) {
SerUtil::serialize(out, it->first); SerUtil::serialize(out, it->first);
serialize(out, it->second); serialize(out, it->second);
...@@ -1104,24 +1132,24 @@ namespace AMDiS { ...@@ -1104,24 +1132,24 @@ namespace AMDiS {
unsigned long tmp = 0; unsigned long tmp = 0;
// vertexElements // vertexElements
tmp = mapOverhead + vertexElements.size() * mapEntryOverhead; tmp = flatMapOverhead;
for (map<DegreeOfFreedom, vector<ElementObjectData> >::iterator mapIt = for (flat_map<DegreeOfFreedom, vector<ElementObjectData> >::iterator mapIt =
vertexElements.begin(); mapIt != vertexElements.end(); ++mapIt) vertexElements.begin(); mapIt != vertexElements.end(); ++mapIt)
tmp += dofSize + vectorOverhead + mapIt->second.size() * structElObjDataSize; tmp += dofSize + vectorOverhead + mapIt->second.size() * structElObjDataSize;
MSG("EL-OBJ-DB MEM 01: %d\n", tmp); MSG("EL-OBJ-DB MEM 01: %d\n", tmp);
value += tmp; value += tmp;
// edgeElements // edgeElements
tmp = mapOverhead + edgeElements.size() * mapEntryOverhead; tmp = flatMapOverhead;
for (map<DofEdge, vector<ElementObjectData> >::iterator mapIt = for (flat_map<DofEdge, vector<ElementObjectData> >::iterator mapIt =
edgeElements.begin(); mapIt != edgeElements.end(); ++mapIt) edgeElements.begin(); mapIt != edgeElements.end(); ++mapIt)
tmp += dofSize + vectorOverhead + mapIt->second.size() * structElObjDataSize; tmp += dofSize + vectorOverhead + mapIt->second.size() * structElObjDataSize;
MSG("EL-OBJ-DB MEM 02: %d\n", tmp); MSG("EL-OBJ-DB MEM 02: %d\n", tmp);
value += tmp; value += tmp;
// faceElements // faceElements
tmp += mapOverhead + faceElements.size() * mapEntryOverhead; tmp = flatMapOverhead;
for (map<DofFace, vector<ElementObjectData> >::iterator mapIt = for (flat_map<DofFace, vector<ElementObjectData> >::iterator mapIt =
faceElements.begin(); mapIt != faceElements.end(); ++mapIt) faceElements.begin(); mapIt != faceElements.end(); ++mapIt)
tmp += dofSize + vectorOverhead + mapIt->second.size() * structElObjDataSize; tmp += dofSize + vectorOverhead + mapIt->second.size() * structElObjDataSize;
MSG("EL-OBJ-DB MEM 03: %d\n", tmp); MSG("EL-OBJ-DB MEM 03: %d\n", tmp);
...@@ -1176,10 +1204,10 @@ namespace AMDiS { ...@@ -1176,10 +1204,10 @@ namespace AMDiS {
tmp += setOverhead + faceReverseMode.size() * (setEntryOverhead + 2 * structElObjDataSize); tmp += setOverhead + faceReverseMode.size() * (setEntryOverhead + 2 * structElObjDataSize);
// macroElIndexMap // macroElIndexMap
tmp += mapOverhead + macroElIndexMap.size() * (mapEntryOverhead + sizeof(int) + sizeof(int*)); tmp += flatMapOverhead + macroElIndexMap.size() * (sizeof(int) + sizeof(int*));
// macroElIndexTypeMap // macroElIndexTypeMap
tmp += mapOverhead + macroElIndexTypeMap.size() * (mapEntryOverhead + sizeof(int) + sizeof(int*)); tmp += flatMapOverhead + macroElIndexTypeMap.size() * (sizeof(int) + sizeof(int));
MSG("EL-OBJ-DB MEM 08: %d\n", tmp); MSG("EL-OBJ-DB MEM 08: %d\n", tmp);
value += tmp; value += tmp;
......
...@@ -50,6 +50,8 @@ namespace AMDiS { ...@@ -50,6 +50,8 @@ namespace AMDiS {
}; };
#pragma pack(push)
#pragma pack(1)
/// Defines one element object. This may be either a vertex, edge or face. /// Defines one element object. This may be either a vertex, edge or face.
struct ElementObjectData { struct ElementObjectData {
ElementObjectData(int a = -1, int b = 0) ElementObjectData(int a = -1, int b = 0)
...@@ -61,7 +63,7 @@ namespace AMDiS { ...@@ -61,7 +63,7 @@ namespace AMDiS {
int elIndex; int elIndex;
/// Index of the object within the element. /// Index of the object within the element.
int ithObject; char ithObject;
/// Write this element object to disk. /// Write this element object to disk.
void serialize(ostream &out) const void serialize(ostream &out) const
...@@ -90,7 +92,7 @@ namespace AMDiS { ...@@ -90,7 +92,7 @@ namespace AMDiS {
(elIndex == rhs.elIndex && ithObject < rhs.ithObject)); (elIndex == rhs.elIndex && ithObject < rhs.ithObject));
} }
}; };
#pragma pack(pop)
/** \brief /** \brief
...@@ -498,15 +500,27 @@ namespace AMDiS { ...@@ -498,15 +500,27 @@ namespace AMDiS {
/// The mesh that is used to store all its element information in /// The mesh that is used to store all its element information in
/// the database. /// the database.
Mesh *mesh; Mesh *mesh;
/// Maps to each vertex DOF all element objects that represent this vertex. /// Maps to each vertex DOF all element objects that represent this vertex.
map<DegreeOfFreedom, vector<ElementObjectData> > vertexElements; flat_map<DegreeOfFreedom, vector<ElementObjectData> > vertexElements;
/// Maps to each edge all element objects that represent this edge. /// Maps to each edge all element objects that represent this edge.
map<DofEdge, vector<ElementObjectData> > edgeElements; flat_map<DofEdge, vector<ElementObjectData> > edgeElements;
/// Maps to each face all element objects that represent this edge. /// Maps to each face all element objects that represent this edge.
map<DofFace, vector<ElementObjectData> > faceElements; flat_map<DofFace, vector<ElementObjectData> > faceElements;
/// Temporary object to speed up creation of \ref vertexElements
map<DegreeOfFreedom, vector<ElementObjectData> > tmpVertexElements;
/// Temporary object to speed up creation of \ref edgeElements
map<DofEdge, vector<ElementObjectData> > tmpEdgeElements;
/// Temporary object to speed up creation of \ref faceElements
map<DofFace, vector<ElementObjectData> > tmpFaceElements;
/// Maps to an element object the corresponding vertex DOF. /// Maps to an element object the corresponding vertex DOF.
...@@ -576,10 +590,10 @@ namespace AMDiS { ...@@ -576,10 +590,10 @@ namespace AMDiS {
map<int, int> *macroElementRankMap; map<int, int> *macroElementRankMap;
/// Maps to each macro element index a pointer to the corresponding element. /// Maps to each macro element index a pointer to the corresponding element.
map<int, Element*> macroElIndexMap; flat_map<int, Element*> macroElIndexMap;
/// Maps to each macro element index the type of this element. /// Maps to each macro element index the type of this element.
map<int, int> macroElIndexTypeMap; flat_map<int, int> macroElIndexTypeMap;
MeshLevelData* levelData; MeshLevelData* levelData;
}; };
......
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