From ab01d6780804aee060432d65b56012650fb91acc Mon Sep 17 00:00:00 2001 From: Thomas Witkowski <thomas.witkowski@gmx.de> Date: Wed, 1 Oct 2008 08:49:45 +0000 Subject: [PATCH] * int calcMemoryUsage() introduced for some classes --- AMDiS/src/DOFVector.h | 44 +++++++++++----------- AMDiS/src/DOFVector.hh | 48 +++++++++++++----------- AMDiS/src/Element.cc | 14 ++++++- AMDiS/src/Element.h | 64 ++++++++++++++++---------------- AMDiS/src/MacroElement.cc | 24 +++++++++--- AMDiS/src/MacroElement.h | 4 +- AMDiS/src/Mesh.cc | 12 ++++++ AMDiS/src/Mesh.h | 16 +++++--- AMDiS/src/SolutionDataStorage.h | 27 ++++---------- AMDiS/src/SolutionDataStorage.hh | 35 ++++++----------- AMDiS/src/SystemVector.h | 19 ++++++++-- 11 files changed, 175 insertions(+), 132 deletions(-) diff --git a/AMDiS/src/DOFVector.h b/AMDiS/src/DOFVector.h index aca25f46..536a9ee0 100644 --- a/AMDiS/src/DOFVector.h +++ b/AMDiS/src/DOFVector.h @@ -319,7 +319,7 @@ namespace AMDiS { feSpace(NULL), refineInter(false), coarsenOperation(NO_OPERATION) - {}; + {} /** \brief * Constructs a DOFVector with name n belonging to FiniteElemSpace f @@ -340,7 +340,7 @@ namespace AMDiS { if (feSpace && feSpace->getAdmin()) { (dynamic_cast<DOFAdmin*>(feSpace->getAdmin()))->addDOFIndexed(this); } - }; + } /** \brief * Destructor @@ -373,59 +373,59 @@ namespace AMDiS { */ inline void refineInterpol(bool b) { refineInter = b; - }; + } /** \brief * Sets \ref coarsenOperation to op */ inline void setCoarsenOperation(CoarsenOperation op) { coarsenOperation = op; - }; + } /** \brief * Returns \ref coarsenOperation */ inline CoarsenOperation getCoarsenOperation() { return coarsenOperation; - }; + } /** \brief * Restriction after coarsening. Implemented for DOFVector<double> */ - inline void coarseRestrict(RCNeighbourList&, int) {}; + inline void coarseRestrict(RCNeighbourList&, int) {} /** \brief * Returns \ref refineInter */ inline bool refineInterpol() { return refineInter; - }; + } /** \brief * Interpolation after refinement. */ - inline void refineInterpol(RCNeighbourList&, int) {}; + inline void refineInterpol(RCNeighbourList&, int) {}; /** \brief * Returns \ref vec */ std::vector<T>& getVector() { return vec; - }; + } /** \brief * Returns size of \ref vec */ inline int getSize() const { return vec.size(); - }; + } /** \brief * Returns used size of the vector. */ inline int getUsedSize() const { return feSpace->getAdmin()->getUsedSize(); - }; + } /** \brief * Resizes \ref vec to n @@ -434,7 +434,7 @@ namespace AMDiS { FUNCNAME("DOFVector<T>::resize()"); TEST_EXIT_DBG((n >= 0))("Can't resize DOFVector to negative size\n"); vec.resize(n); - }; + } /** \brief * Resizes \ref vec to n and inits new values with init @@ -443,7 +443,7 @@ namespace AMDiS { FUNCNAME("DOFVector<T>::resize()"); TEST_EXIT_DBG((n >= 0))("Can't resize DOFVector to negative size\n"); vec.resize(n, init); - }; + } /** \brief * Returns \ref vec[i] @@ -453,11 +453,11 @@ namespace AMDiS { TEST_EXIT_DBG((i>= 0) && (i < static_cast<int>(vec.size()))) ("Illegal vector index %d.\n",i); return vec[i]; - }; + } inline int getSize() { return vec.size(); - }; + } /** \brief * Returns \ref vec[i] @@ -467,7 +467,7 @@ namespace AMDiS { TEST_EXIT_DBG((i >= 0) && (i < static_cast<int>(vec.size()))) ("Illegal vector index %d.\n",i); return vec[i]; - }; + } /** \brief * Calculates Integral of this DOFVector @@ -518,7 +518,7 @@ namespace AMDiS { */ inline double l2norm() const { return nrm2(); - }; + } /** \brief * Calculates the absolute sum of this DOFVector @@ -530,7 +530,7 @@ namespace AMDiS { */ inline double l1norm() const { return asum(); - }; + } /** \brief * Calculates doublewell of this DOFVector @@ -553,7 +553,7 @@ namespace AMDiS { inline DOFVector<T>& operator=(T d) { set(d); return *this; - }; + } /** \brief * Assignment operator between two vectors @@ -590,6 +590,8 @@ namespace AMDiS { */ void print() const; + int calcMemoryUsage() const; + /** \brief * Computes the coefficients of the interpolant of the function fct and * stores these in the DOFVector @@ -604,14 +606,14 @@ namespace AMDiS { unsigned int size = vec.size(); out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int)); out.write(reinterpret_cast<const char*>(&(vec[0])), size * sizeof(T)); - }; + } void deserialize(std::istream &in) { unsigned int size; in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int)); vec.resize(size); in.read(reinterpret_cast<char*>(&(vec[0])), size * sizeof(T)); - }; + } DOFVector<WorldVector<T> > *getGradient(DOFVector<WorldVector<T> >*) const; diff --git a/AMDiS/src/DOFVector.hh b/AMDiS/src/DOFVector.hh index e58c6449..a8b4aa2c 100644 --- a/AMDiS/src/DOFVector.hh +++ b/AMDiS/src/DOFVector.hh @@ -403,15 +403,15 @@ namespace AMDiS { template<typename T> void DOFVector<T>::print() const { - FUNCNAME("DOFVector<T>::print"); - int i, j; + FUNCNAME("DOFVector<T>::print()"); const DOFAdmin *admin = NULL; - const char *format; + const char *format; - if (feSpace) admin = feSpace->getAdmin(); + if (feSpace) + admin = feSpace->getAdmin(); MSG("Vec `%s':\n", name.c_str()); - j = 0; + int j = 0; if (admin) { if (admin->getUsedSize() > 100) format = "%s(%3d,%10.5le)"; @@ -424,27 +424,25 @@ namespace AMDiS { for(vecIterator.reset(); !vecIterator.end(); ++vecIterator) { if ((j % 3) == 0) { - if (j) Msg::print("\n"); + if (j) + Msg::print("\n"); MSG(format, "", vecIterator.getDOFIndex(), *vecIterator); - } - else + } else Msg::print(format, " ", vecIterator.getDOFIndex(), *vecIterator); j++; - }; + } Msg::print("\n"); - } - else - { + } else { MSG("no DOFAdmin, print whole vector.\n"); - for (i = 0; i < static_cast<int>( vec.size()); i++) { - if ((j % 3) == 0) - { - if (j) Msg::print("\n"); - MSG("(%d,%10.5e)",i,vec[i]); - } - else + for (int i = 0; i < static_cast<int>( vec.size()); i++) { + if ((j % 3) == 0) { + if (j) + Msg::print("\n"); + MSG("(%d,%10.5e)",i,vec[i]); + } else { Msg::print(" (%d,%10.5e)",i,vec[i]); + } j++; } Msg::print("\n"); @@ -452,17 +450,25 @@ namespace AMDiS { return; } + template<typename T> + int DOFVector<T>::calcMemoryUsage() const + { + int result = 0; + result += sizeof(DOFVector<T>); + result += vec.size() * sizeof(T); + + return result; + } template<typename T> T DOFVectorBase<T>::evalUh(const DimVec<double>& lambda, DegreeOfFreedom* dof_indices) { - int i; BasisFunction* phi = const_cast<BasisFunction*>(this->getFESpace()->getBasisFcts()); int numberOfBasFcts = phi->getNumber(); T val = 0.0; - for (i = 0; i < numberOfBasFcts; i++) + for (int i = 0; i < numberOfBasFcts; i++) val += (*this)[dof_indices[i]]*(*phi->getPhi(i))(lambda); return val; diff --git a/AMDiS/src/Element.cc b/AMDiS/src/Element.cc index 94f62732..b853cb1d 100644 --- a/AMDiS/src/Element.cc +++ b/AMDiS/src/Element.cc @@ -255,7 +255,7 @@ namespace AMDiS { void Element::serialize(std::ostream &out) { // write children - if(child[0]) { + if (child[0]) { out << child[0]->getTypeName() << "\n"; child[0]->serialize(out); child[1]->serialize(out); @@ -420,4 +420,16 @@ namespace AMDiS { } } + int Element::calcMemoryUsage() + { + int result = 0; + + result += sizeof(Element); + if (child[0]) { + result += child[0]->calcMemoryUsage() + child[1]->calcMemoryUsage(); + } + + return result; + } + } diff --git a/AMDiS/src/Element.h b/AMDiS/src/Element.h index 830b1f5d..c9daec1e 100644 --- a/AMDiS/src/Element.h +++ b/AMDiS/src/Element.h @@ -112,14 +112,14 @@ namespace AMDiS { */ inline Element* getFirstChild() const { return child[0]; - }; + } /** \brief * Returns \ref child[1] */ inline Element* getSecondChild() const { return child[1]; - }; + } /** \brief * Returns \ref child[i], i=0,1 @@ -127,7 +127,7 @@ namespace AMDiS { inline Element* getChild(int i) const { TEST_EXIT_DBG(i==0 || i==1)("i must be 0 or 1\n"); return child[i]; - }; + } /** \brief * Returns true if Element is a leaf element (\ref child[0] == NULL), returns @@ -135,35 +135,35 @@ namespace AMDiS { */ inline const bool isLeaf() const { return (child[0] == NULL); - }; + } /** \brief * Returns \ref dof[i][j] which is the j-th DOF of the i-th node of Element. */ const DegreeOfFreedom getDOF(int i, int j) const { return dof[i][j]; - }; + } /** \brief * Returns \ref dof[i] which is a pointer to the DOFs of the i-th node. */ const DegreeOfFreedom* getDOF(int i) const { return dof[i]; - }; + } /** \brief * Returns a pointer to the DOFs of this Element */ const DegreeOfFreedom** getDOF() const { return const_cast<const DegreeOfFreedom**>(dof); - }; + } /** \brief * Returns \ref mesh of Element */ inline Mesh* getMesh() const { return mesh; - }; + } /** \brief * Returns \ref elementData's error estimation, if Element is a leaf element @@ -180,7 +180,7 @@ namespace AMDiS { } return 0.0; - }; + } /** \brief * Returns Element's coarsening error estimation, if Element is a leaf @@ -196,7 +196,7 @@ namespace AMDiS { } return 0.0; - }; + } /** \brief * Returns region of element if defined, -1 else. @@ -236,7 +236,7 @@ namespace AMDiS { */ inline const signed char getMark() const { return mark; - }; + } /** \brief * Returns \ref newCoord[i] @@ -248,14 +248,14 @@ namespace AMDiS { */ inline int getIndex() const { return index; - }; + } /** \brief * Returns \ref newCoord */ inline WorldVector<double>* getNewCoord() const { return newCoord; - }; + } /** \} */ @@ -270,21 +270,21 @@ namespace AMDiS { */ virtual void setFirstChild(Element *aChild) { child[0] = aChild; - }; + } /** \brief * Sets \ref child[1] */ virtual void setSecondChild(Element *aChild) { child[1] = aChild; - }; + } /** \brief * Sets \ref elementData of Element */ void setElementData(ElementData* ed) { elementData = ed; - }; + } /** \brief * Sets \ref newCoord of Element. Needed by refinement, if Element has a @@ -292,14 +292,14 @@ namespace AMDiS { */ inline void setNewCoord(WorldVector<double>* coord) { newCoord = coord; - }; + } /** \brief * Sets \ref mesh. */ inline void setMesh(Mesh *m) { mesh = m; - }; + } /** \brief * Sets the pointer to the DOFs of the i-th node of Element @@ -307,7 +307,7 @@ namespace AMDiS { DegreeOfFreedom* setDOF(int pos, DegreeOfFreedom* p) { dof[pos] = p; return dof[pos]; - }; + } /** \brief * Checks whether Element is a leaf element and whether it has leaf data. @@ -325,7 +325,7 @@ namespace AMDiS { } else { ERROR_EXIT("setEstimation only for leaf elements!\n"); } - }; + } /** \brief * Sets Element's coarsening error estimation, if Element is a leaf element @@ -343,7 +343,7 @@ namespace AMDiS { } else { ERROR_EXIT("setEstimation only for leaf elements!\n"); } - }; + } /** \brief * Sets Elements \ref mark = mark + 1; @@ -358,14 +358,14 @@ namespace AMDiS { inline void decrementMark() { if (0 < mark) mark--; - }; + } /** \brief * Sets Element's \ref mark */ inline void setMark(signed char m) { mark = m; - }; + } /** \} */ @@ -451,7 +451,7 @@ namespace AMDiS { elementData = tmp; } } - }; + } /** \brief * Coarsens Element's leaf data @@ -470,14 +470,14 @@ namespace AMDiS { DELETE childData; child2->setElementData(NULL); } - }; + } /** \brief * Returns pointer to \ref elementData */ inline ElementData* getElementData() const { return elementData; - }; + } /** \brief * @@ -487,7 +487,7 @@ namespace AMDiS { return elementData->getElementData(typeID); } return NULL; - }; + } /** \brief * kills \ref elementData @@ -505,7 +505,7 @@ namespace AMDiS { } } return false; - }; + } /** \brief * Returns whether element is refined at side side @@ -521,7 +521,7 @@ namespace AMDiS { */ inline bool isNewCoordSet() const { return (newCoord != NULL); - }; + } /** \brief * Frees memory for \ref newCoord @@ -534,6 +534,8 @@ namespace AMDiS { void deserialize(std::istream &in); + int calcMemoryUsage(); + // ===== protected methods ==================================================== protected: /** \brief @@ -546,7 +548,7 @@ namespace AMDiS { */ inline void setIndex(int i) { index = i; - }; + } /** \brief * Used by friend class Mesh while dofCompress @@ -575,7 +577,7 @@ namespace AMDiS { * present, then those at the faces, if present, and then those at the * barycenter, if present. */ - DegreeOfFreedom **dof; + DegreeOfFreedom **dof; /** \brief * Unique global index of the element. these indices are not strictly ordered diff --git a/AMDiS/src/MacroElement.cc b/AMDiS/src/MacroElement.cc index b3dd85cf..427e032c 100644 --- a/AMDiS/src/MacroElement.cc +++ b/AMDiS/src/MacroElement.cc @@ -93,14 +93,14 @@ namespace AMDiS { element->deserialize(in); // read coords - int i, size; + int size; in.read(reinterpret_cast<char*>(&size), sizeof(int)); if (coord.getSize()) { TEST_EXIT(coord.getSize() == size)("invalid size\n"); } else { coord.initSize(size); } - for(i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { coord[i].deserialize(in); } @@ -110,13 +110,13 @@ namespace AMDiS { // read projection in.read(reinterpret_cast<char*>(&size), sizeof(int)); - if(projection.getSize()) { + if (projection.getSize()) { TEST_EXIT(projection.getSize() == size)("invalid size\n"); } else { projection.initSize(size); } - for(i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { int id; in.read(reinterpret_cast<char*>(&id), sizeof(int)); projection[i] = (id != -1) ? Projection::getProjection(id) : NULL; @@ -136,7 +136,7 @@ namespace AMDiS { neighbour.initSize(size); } - for(i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { int index; in.read(reinterpret_cast<char*>(&index), sizeof(int)); @@ -161,4 +161,18 @@ namespace AMDiS { in.read(reinterpret_cast<char*>(&elType), sizeof(unsigned char)); } + int MacroElement::calcMemoryUsage() + { + int result = 0; + + result += sizeof(MacroElement); + result += coord.getSize() * sizeof(WorldVector<double>); + result += projection.getSize() * sizeof(Projection*); + result += neighbour.getSize() * sizeof(MacroElement*); + result += oppVertex.getSize() * sizeof(char); + result += element->calcMemoryUsage(); + + return result; + } + } diff --git a/AMDiS/src/MacroElement.h b/AMDiS/src/MacroElement.h index 90555e49..a1aab528 100644 --- a/AMDiS/src/MacroElement.h +++ b/AMDiS/src/MacroElement.h @@ -211,7 +211,9 @@ namespace AMDiS { inline void writeNeighboursTo(std::vector<int> *indices) { deserializedNeighbourIndices_ = indices; - }; + } + + int calcMemoryUsage(); protected: /** \brief diff --git a/AMDiS/src/Mesh.cc b/AMDiS/src/Mesh.cc index 9ade143d..89ea32f8 100644 --- a/AMDiS/src/Mesh.cc +++ b/AMDiS/src/Mesh.cc @@ -1101,4 +1101,16 @@ namespace AMDiS { getNumberOfVertices()); DELETE macroFileInfo_; } + + int Mesh::calcMemoryUsage() + { + int result = 0; + + result += sizeof(Mesh); + for (int i = 0; i < static_cast<int>(macroElements.size()); i++) { + result += macroElements[i]->calcMemoryUsage(); + } + + return result; + } } diff --git a/AMDiS/src/Mesh.h b/AMDiS/src/Mesh.h index 962ef0c3..91fab922 100644 --- a/AMDiS/src/Mesh.h +++ b/AMDiS/src/Mesh.h @@ -514,7 +514,7 @@ namespace AMDiS { */ inline void clearMacroElements() { macroElements.clear(); - }; + } /** \brief * Adds a macro element to the mesh @@ -597,7 +597,7 @@ namespace AMDiS { ERROR_EXIT("invalid dim\n"); return FILL_ANY_1D; } - }; + }; // ===== Serializable implementation ===== @@ -610,16 +610,18 @@ namespace AMDiS { */ inline int getNextElementIndex() { return elementIndex++; - }; + } /** \brief * Returns \ref initialized. */ - inline bool isInitialized() { return initialized; }; + inline bool isInitialized() { + return initialized; + } inline std::map<BoundaryType, VertexVector*>& getPeriodicAssociations() { return periodicAssociations; - }; + } bool associated(DegreeOfFreedom dof1, DegreeOfFreedom dof2); @@ -627,10 +629,12 @@ namespace AMDiS { inline MacroInfo* getMacroFileInfo() { return macroFileInfo_; - }; + } void clearMacroFileInfo(); + int calcMemoryUsage(); + public: /** \brief * diff --git a/AMDiS/src/SolutionDataStorage.h b/AMDiS/src/SolutionDataStorage.h index 87c312d3..8d64cc98 100644 --- a/AMDiS/src/SolutionDataStorage.h +++ b/AMDiS/src/SolutionDataStorage.h @@ -38,24 +38,20 @@ namespace AMDiS { /** \brief * Set one fix FE Space. All solutions are defined only on the given FE Space. */ - void setFixFESpace(typename SolutionHelper<T>::type feSpace, - bool cleanupFeSpace = false); + void setFixFESpace(typename SolutionHelper<T>::type feSpace); /** \brief * */ void push(T *solution, - double timestamp, - bool cleanupSolution = true); + double timestamp); /** \brief * */ void push(T *solution, double timestamp, - typename SolutionHelper<T>::type feSpace, - bool cleanupSolution = true, - bool cleanupFeSpace = true); + typename SolutionHelper<T>::type feSpace); /** \brief * @@ -136,18 +132,6 @@ namespace AMDiS { */ std::vector<double> timestamps; - /** \brief - * Stores to each solution, if the data storage is allowed to delete - * the solution by itself. - */ - std::vector<bool> cleanupSolutions; - - /** \brief - * Stores to each fe space, if the data storage is allowed to delete - * the fe space by itself. - */ - std::vector<bool> cleanupFeSpaces; - /** \brief * Position of the latest valid solution. */ @@ -157,6 +141,11 @@ namespace AMDiS { * If true, the last operation on the data storage was pop. */ bool poped; + + /** \brief + * Counts the memory usage of all solutions stored in memory. + */ + int memoryUsage; }; } diff --git a/AMDiS/src/SolutionDataStorage.hh b/AMDiS/src/SolutionDataStorage.hh index cbcb1709..a725e2bf 100644 --- a/AMDiS/src/SolutionDataStorage.hh +++ b/AMDiS/src/SolutionDataStorage.hh @@ -12,8 +12,6 @@ namespace AMDiS { solutions.empty(); feSpaces.empty(); timestamps.empty(); - cleanupSolutions.empty(); - cleanupFeSpaces.empty(); int tmp = 0; GET_PARAMETER(0, name + "->memory usage", "%d", &maxMemoryUsage); @@ -29,8 +27,7 @@ namespace AMDiS { } template<typename T> - void SolutionDataStorage<T>::setFixFESpace(typename SolutionHelper<T>::type feSpace, - bool cleanupFeSpace) + void SolutionDataStorage<T>::setFixFESpace(typename SolutionHelper<T>::type feSpace) { FUNCNAME("SolutionDataStorage::setFixFESpace()"); @@ -38,13 +35,14 @@ namespace AMDiS { fixedFESpace = true; feSpaces.push_back(feSpace); - cleanupFeSpaces.push_back(cleanupFeSpace); + + std::cout << "MESH = " << static_cast<double>(feSpace[0]->getMesh()->calcMemoryUsage()) / (1024.0 * 1024.0) << std::endl; + WAIT_REALLY; } template<typename T> void SolutionDataStorage<T>::push(T *solution, - double timestamp, - bool cleanupSolution) + double timestamp) { // If pop was the last operation, cleanup and reset the data storage. if (poped) { @@ -54,24 +52,21 @@ namespace AMDiS { solutions.push_back(solution); timestamps.push_back(timestamp); - cleanupSolutions.push_back(cleanupSolution); lastPos++; + memoryUsage += solution->calcMemoryUsage(); } template<typename T> void SolutionDataStorage<T>::push(T *solution, double timestamp, - typename SolutionHelper<T>::type feSpace, - bool cleanupSolution, - bool cleanupFeSpace) + typename SolutionHelper<T>::type feSpace) { - push(solution, timestamp, cleanupSolution, cleanupFeSpace); + push(solution, timestamp); // Store fe space only, if we do not have a fixed fe space. if (!fixedFESpace) { feSpaces.push_back(feSpace); - cleanupFeSpaces.push_back(cleanupFeSpace); } } @@ -113,20 +108,14 @@ namespace AMDiS { template<typename T> void SolutionDataStorage<T>::cleanup() { - for (int i = 0; i < static_cast<int>(cleanupSolutions.size()); i++) { - if (cleanupSolutions[i]) { - DELETE solutions[i]; - } + for (int i = 0; i < static_cast<int>(solutions.size()); i++) { + DELETE solutions[i]; } - for (int i = 0; i < static_cast<int>(cleanupFeSpaces.size()); i++) { - if (cleanupFeSpaces[i]) { - deleteFeSpace(feSpaces[i]); - } + for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) { + deleteFeSpace(feSpaces[i]); } - cleanupSolutions.empty(); - cleanupFeSpaces.empty(); solutions.empty(); feSpaces.empty(); timestamps.empty(); diff --git a/AMDiS/src/SystemVector.h b/AMDiS/src/SystemVector.h index 0117ba84..71aabaef 100644 --- a/AMDiS/src/SystemVector.h +++ b/AMDiS/src/SystemVector.h @@ -61,12 +61,12 @@ namespace AMDiS { : name(name_), feSpace(feSpace_), size(size_) - {}; + {} /** \brief * Destructor */ - virtual ~Creator() {}; + virtual ~Creator() {} /** \brief * Implementation of CreatorInterface::create(). @@ -81,7 +81,7 @@ namespace AMDiS { result->setDOFVector(i, NEW DOFVector<double>(feSpace[i], numberedName)); } return result; - }; + } /** \brief * Implementation of CreatorInterface::free(). @@ -92,7 +92,7 @@ namespace AMDiS { vec->setDOFVector(i, NULL); } DELETE vec; - }; + } private: /** \brief @@ -316,7 +316,17 @@ namespace AMDiS { } } + int calcMemoryUsage() { + int result = 0; + + for (int i = 0; i < static_cast<int>(vectors.getSize()); i++) { + result += vectors[i]->calcMemoryUsage(); + } + + return result; + } + protected: /** \brief @@ -335,6 +345,7 @@ namespace AMDiS { Vector<DOFVector<double>*> vectors; }; + /** \brief * multiplication with scalar */ -- GitLab