diff --git a/AMDiS/src/DOFAdmin.cc b/AMDiS/src/DOFAdmin.cc index afd2d21a3223917b585477a198d2571f445da294..6b6ec752bdae3c8d7f9869b29877a8b1404ce4c3 100755 --- a/AMDiS/src/DOFAdmin.cc +++ b/AMDiS/src/DOFAdmin.cc @@ -340,6 +340,11 @@ namespace AMDiS { { } + int DOFAdmin::calcMemoryUsage() + { + return sizeof(DOFAdmin); + } + void DOFAdmin::serialize(std::ostream &out) { // write name diff --git a/AMDiS/src/DOFAdmin.h b/AMDiS/src/DOFAdmin.h index d3bc87f66664894952ed48d96d5d5e88961fce1d..c327d85583c23e2ab703fdce218ae36dec331368 100644 --- a/AMDiS/src/DOFAdmin.h +++ b/AMDiS/src/DOFAdmin.h @@ -284,6 +284,8 @@ namespace AMDiS { mesh = m; } + int calcMemoryUsage(); + /** \} */ protected: diff --git a/AMDiS/src/Element.cc b/AMDiS/src/Element.cc index 0b3150cb3b535e71110a27f72865234fb53032f3..152e10d676b74f70afe5f5d5d3787ba7bbd75b9f 100644 --- a/AMDiS/src/Element.cc +++ b/AMDiS/src/Element.cc @@ -545,6 +545,8 @@ namespace AMDiS { int result = 0; result += sizeof(Element); + result += mesh->getNumberOfNodes() * sizeof(DegreeOfFreedom*); + if (child[0]) { result += child[0]->calcMemoryUsage() + child[1]->calcMemoryUsage(); } diff --git a/AMDiS/src/FiniteElemSpace.cc b/AMDiS/src/FiniteElemSpace.cc index 0370144fda3e9b7ef0d07519116097dee1a283d0..b3fc47da9a81ad2e83619761d123197efd83dc3f 100644 --- a/AMDiS/src/FiniteElemSpace.cc +++ b/AMDiS/src/FiniteElemSpace.cc @@ -97,10 +97,20 @@ namespace AMDiS { } } + int FiniteElemSpace::calcMemoryUsage() + { + int result = sizeof(FiniteElemSpace); + result += mesh->calcMemoryUsage(); + return result; + } + void FiniteElemSpace::clear() { - for (int i = 0; i < feSpaces.size(); i++) { - DELETE feSpaces[i]; + for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) { + if (feSpaces[i]) { + DELETE feSpaces[i]; + feSpaces[i] = NULL; + } } } } diff --git a/AMDiS/src/FiniteElemSpace.h b/AMDiS/src/FiniteElemSpace.h index 55c061d031e69e699d3599c90fe2d176e6d39cd6..7cf8c56c7e27bd38da1e70fd06b87ad564c1fa99 100644 --- a/AMDiS/src/FiniteElemSpace.h +++ b/AMDiS/src/FiniteElemSpace.h @@ -106,6 +106,8 @@ namespace AMDiS { return mesh; } + int calcMemoryUsage(); + static void clear(); protected: @@ -116,7 +118,7 @@ namespace AMDiS { FiniteElemSpace(DOFAdmin* admin_, const BasisFunction* basisFcts, Mesh* mesh, - const std::string& name_ = ""); + const std::string& name = ""); protected: /** \brief diff --git a/AMDiS/src/Lagrange.cc b/AMDiS/src/Lagrange.cc index 8a6ac65ad32f991934111faf3dc2e511b1278ab9..4ebf8f8b40441dd4af1bfb851045393974459738 100644 --- a/AMDiS/src/Lagrange.cc +++ b/AMDiS/src/Lagrange.cc @@ -75,7 +75,10 @@ namespace AMDiS { { std::list<Lagrange*>::iterator it; for (it = allBasFcts.begin(); it != allBasFcts.end(); it++) { - DELETE *it; + if (*it) { + DELETE *it; + *it = NULL; + } } } diff --git a/AMDiS/src/Mesh.cc b/AMDiS/src/Mesh.cc index 5af9d8dfad381f12a9c39abb839c7fbd6b9e52c3..a153f20ee73e14ae9deffbabf10406c784e52d5f 100644 --- a/AMDiS/src/Mesh.cc +++ b/AMDiS/src/Mesh.cc @@ -1058,6 +1058,12 @@ namespace AMDiS { { int result = sizeof(Mesh); + result += nDOFEl; + for (int i = 0; i < static_cast<int>(admin.size()); i++) { + result += admin[i]->calcMemoryUsage(); + result += admin[i]->getUsedSize() * sizeof(DegreeOfFreedom); + } + for (int i = 0; i < static_cast<int>(macroElements.size()); i++) { result += macroElements[i]->calcMemoryUsage(); } diff --git a/AMDiS/src/SolutionDataStorage.h b/AMDiS/src/SolutionDataStorage.h index bbf67af0ded1eeed641fb8aff241e1a21d827937..48c1fb640293302326aaa306f9f05ea94a9f1d8c 100644 --- a/AMDiS/src/SolutionDataStorage.h +++ b/AMDiS/src/SolutionDataStorage.h @@ -53,26 +53,12 @@ namespace AMDiS { void push(T *solution, double timestamp); - /** \brief - * - */ - void push(T *solution, - typename SolutionHelper<T>::type feSpace, - double timestamp); - /** \brief * */ bool pop(T **solution, double *timestep); - /** \brief - * - */ - bool pop(T **solution, - typename SolutionHelper<T>::type feSpace, - double *timestep); - /** \brief * Deletes all pointers and empties all internal vectors. */ @@ -88,18 +74,36 @@ namespace AMDiS { return feSpaces[i]; } + /** \brief + * + */ bool isPoped() { return poped; } + /** \brief + * + */ void addContainer(std::string name); + /** \brief + * + */ void push(std::string name, WorldVector<double> value); + /** \brief + * + */ void pop(std::string name, WorldVector<double> &value); + /** \brief + * + */ void reset(std::string name); + /** \brief + * + */ void clear(std::string name); protected: @@ -120,10 +124,16 @@ namespace AMDiS { feSpaces.clear(); } + /** \brief + * + */ int addMemoryUsage(FiniteElemSpace* feSpace) { memoryUsage += feSpace->getMesh()->calcMemoryUsage(); } + /** \brief + * + */ int addMemoryUsage(std::vector<FiniteElemSpace*> feSpaces) { // Is used to determine equal meshes for different components. std::vector<Mesh*> meshes; @@ -190,8 +200,14 @@ namespace AMDiS { */ int memoryUsage; + /** \brief + * + */ std::map<std::string, std::vector<WorldVector<double > > > containers; + /** \brief + * + */ std::map<std::string, int> containersPos; }; diff --git a/AMDiS/src/SolutionDataStorage.hh b/AMDiS/src/SolutionDataStorage.hh index 09fc5bbcb99a555e90dd28075b3a49afd20906a8..09db6a3bc3284b2d0cbec6e984f90b84340fbf82 100644 --- a/AMDiS/src/SolutionDataStorage.hh +++ b/AMDiS/src/SolutionDataStorage.hh @@ -7,7 +7,8 @@ namespace AMDiS { writeDirectory(""), fixedFESpace(false), lastPos(-1), - poped(false) + poped(false), + memoryUsage(0) { solutions.empty(); feSpaces.empty(); @@ -43,34 +44,37 @@ namespace AMDiS { void SolutionDataStorage<T>::push(T *solution, double timestamp) { + FUNCNAME("SolutionDataStorage<T>::push()"); + + if (fixedFESpace) { + ERROR_EXIT("Not yet\n"); + } + + std::vector<FiniteElemSpace*> feSpace(solution->getFESpaces().size()); + for (int i = 0; i < feSpace.size(); i++) { + feSpace[i] = NEW FiniteElemSpace(); + *(feSpace[i]) = *(solution->getFESpace(i)); + memoryUsage += feSpace[i]->calcMemoryUsage(); + } + + feSpaces.push_back(feSpace); + + SystemVector *vec = NEW SystemVector("tmp", feSpace, solution->getFESpaces().size()); + vec->createNewDOFVectors("tmp"); + vec->setCoarsenOperation(COARSE_INTERPOL); + vec->interpol(solution, 1.0); + memoryUsage += vec->calcMemoryUsage(); + // If pop was the last operation, cleanup and reset the data storage. if (poped) { clear(); poped = false; } - solutions.push_back(solution); + solutions.push_back(vec); timestamps.push_back(timestamp); lastPos++; - // memoryUsage += solution->calcMemoryUsage(); - } - - template<typename T> - void SolutionDataStorage<T>::push(T *solution, - typename SolutionHelper<T>::type feSpace, - double timestamp) - { - FUNCNAME("SolutionDataStorage<T>::push()"); - - push(solution, timestamp); - - // Store fe space only, if we do not have a fixed fe space. - TEST_EXIT(!fixedFESpace)("push wit fe space not possible!\n"); - - if (!fixedFESpace) { - feSpaces.push_back(feSpace); - } } template<typename T> @@ -90,25 +94,6 @@ namespace AMDiS { return true; } - template<typename T> - bool SolutionDataStorage<T>::pop(T **solution, - typename SolutionHelper<T>::type feSpace, - double *timestep) - - { - if (!pop(solution, timestep)) - return false; - - if (!fixedFESpace) { - feSpace = feSpaces[lastPos + 1]; // + 1, because lastPos was decremented in pop call above - } else { - feSpace = feSpaces[0]; - } - - return true; - } - - template<typename T> void SolutionDataStorage<T>::clear() { @@ -127,6 +112,7 @@ namespace AMDiS { timestamps.clear(); lastPos = -1; + memoryUsage = 0; } template<typename T> diff --git a/AMDiS/src/SystemVector.h b/AMDiS/src/SystemVector.h index 9f056c0fd3f75d87d1b02e4b01e9b38701eb7e3a..b1386bd976d0af92896a7af81fedfc36be6259b8 100644 --- a/AMDiS/src/SystemVector.h +++ b/AMDiS/src/SystemVector.h @@ -341,6 +341,8 @@ namespace AMDiS { result += vectors[i]->calcMemoryUsage(); } + result += sizeof(SystemVector); + return result; }