diff --git a/AMDiS/src/MemoryManager.cc b/AMDiS/src/MemoryManager.cc index 9fca0a6fb7e1da76530a396c94f0e8d3c3ad59c5..bc7b3019c66ea0f90e51a31565abb31ba768e483 100644 --- a/AMDiS/src/MemoryManager.cc +++ b/AMDiS/src/MemoryManager.cc @@ -10,7 +10,7 @@ namespace AMDiS { void MemoryManagerBase::addMemoryMonitor(MemoryMonitor* monitor) { memoryMonitors.push_back(monitor); std::vector<MemoryManagerBase*>::iterator it; - for(it = memoryManagers.begin(); it != memoryManagers.end(); it++) { + for (it = memoryManagers.begin(); it != memoryManagers.end(); it++) { monitor->addInstanceCounter((*it)->newInstanceCounter()); } } @@ -18,7 +18,7 @@ namespace AMDiS { void MemoryManagerBase::removeMemoryMonitor(MemoryMonitor* monitor) { std::vector<MemoryMonitor*>::iterator it; it = find(memoryMonitors.begin(), memoryMonitors.end(), monitor); - if(it != memoryMonitors.end()) { + if (it != memoryMonitors.end()) { memoryMonitors.erase(it); } } diff --git a/AMDiS/src/MemoryManager.h b/AMDiS/src/MemoryManager.h index 8c69fc7c46ebc7b6d05f4bfc97a1e11b9fbddeef..32059d64bb144d866d7e6cd47043dc017cec171e 100644 --- a/AMDiS/src/MemoryManager.h +++ b/AMDiS/src/MemoryManager.h @@ -69,7 +69,7 @@ namespace AMDiS { /** \brief * Destructor does nothing */ - virtual ~MemoryManagerBase() {}; + virtual ~MemoryManagerBase() {} /** \brief * Prints the number of currently allocated bytes (\ref byteCount) and for @@ -88,8 +88,8 @@ namespace AMDiS { MSG("memory statistics:\n"); MSG("==================\n"); MSG("byte count: %ld\n", byteCount); - for(it = memoryManagers.begin(); it != memoryManagers.end(); it++) { - if((*it)->instanceCount != 0) { + for (it = memoryManagers.begin(); it != memoryManagers.end(); it++) { + if ((*it)->instanceCount != 0) { MSG("%s, id = %ld : %ld instance%s", (*it)->getName().c_str(), (*it)->typeId, (*it)->instanceCount,((*it)->instanceCount > 1)?pl:sg); // if((*it)->instanceCount > 1) @@ -98,7 +98,7 @@ namespace AMDiS { } } MSG("================================================================\n"); - }; + } /** \brief * Must be overriden for concrete MemoryManagers. Returns the name of @@ -112,14 +112,14 @@ namespace AMDiS { */ inline unsigned long int getInstanceCount() { return instanceCount; - }; + } /** \brief * Returns the number of currently allocated bytes (\ref typedByteCount). */ inline unsigned long int getTypedByteCount() { return typedByteCount; - }; + } /** \brief * Returns a new InstanceCounter for concrete type @@ -148,7 +148,7 @@ namespace AMDiS { public: bool operator()(MemoryManagerBase *a, MemoryManagerBase *b) { return (a->getInstanceCount() > b->getInstanceCount()); - }; + } }; protected: @@ -231,7 +231,7 @@ namespace AMDiS { /** \brief * Constructor */ - MemoryManager() {}; + MemoryManager() {} public: /** \brief @@ -269,7 +269,7 @@ namespace AMDiS { preallocatable ? reinterpret_cast<T*>(MemoryPool::getMemory(s)) : reinterpret_cast<T*>(new char[s]); - }; + } /** \brief * Frees memory which was allocated by \ref getMemory(). If \ref printInfo @@ -289,54 +289,49 @@ namespace AMDiS { preallocatable ? MemoryPool::freeMemory(mem, s) : delete [] (reinterpret_cast<char*>(mem)); - }; + } /** \brief * Returns name of T by demangle the mangled typeid of T. */ inline std::string getName() { -#if 0 - char result[100]; - // demangle(typeid(T).name(), result); - int status; - size_t length; - abi::__cxa_demangle(typeid(T).name(), result, &length, &status); - TEST_EXIT_DBG(status == 0)("demangling failed\n"); - return std::string(result); -#endif return typeid(T).name(); - }; + } /** \brief * Sets \ref preallocatable */ static void setPreallocatable(bool prealloc) { preallocatable = prealloc; - }; + } /** \brief * Sets \ref printInfo */ static void setPrintInfo(bool p) { printInfo = p; - }; + } /** \brief * Returns \ref printInfo */ - static bool getPrintInfo() { return printInfo; }; + static bool getPrintInfo() { + return printInfo; + } /** \brief * Returns the pointer to the \ref singleton instance of MemoryManager<T> */ - static MemoryManager<T>* getSingleton() { return singleton; }; + static MemoryManager<T>* getSingleton() { + return singleton; + } /** \brief * Implementation of \ref MemoryManagerBase::newInstanceCounter() */ InstanceCounterBase* newInstanceCounter() { return new InstanceCounter<T>; - }; + } protected: /** \brief @@ -417,7 +412,7 @@ namespace AMDiS { */ InstanceCounter() : oldInstanceCount(MemoryManager<T>::getSingleton()->getInstanceCount()) - {}; + {} /** \brief * Sets \ref oldInstanceCount to the current number of instances in @@ -425,7 +420,7 @@ namespace AMDiS { */ inline void reset() { oldInstanceCount = MemoryManager<T>::getSingleton()->getInstanceCount(); - }; + } /** \brief * Returns the difference between the current instanceCount and @@ -434,14 +429,14 @@ namespace AMDiS { long int getInstanceCount() { return (MemoryManager<T>::getSingleton()->getInstanceCount() - oldInstanceCount); - }; + } /** \brief * Returns the name of T. Calls MemoryManager<T>::getName() */ std::string getTypeName() { return MemoryManager<T>::getSingleton()->getName(); - }; + } protected: /** \brief @@ -473,10 +468,11 @@ namespace AMDiS { * Constructor. Registers itself with MemoryMonitorBase. */ MemoryMonitor(const char *name_, const char *filename_=NULL) - : name(name_), filename(filename_) + : name(name_), + filename(filename_) { MemoryManagerBase::addMemoryMonitor(this); - }; + } /** \brief * Destructor. Prints statistics and deregisters itself with @@ -485,7 +481,7 @@ namespace AMDiS { ~MemoryMonitor() { printStatistics(); MemoryManagerBase::removeMemoryMonitor(this); - }; + } /** \brief * Prints a statistic for every data type with instanceCount - @@ -495,7 +491,7 @@ namespace AMDiS { FUNCNAME("MemoryMonitor::printStatistics()"); std::ostream *oldOut; static bool fileOpen = false; - if(filename && !fileOpen) { + if (filename && !fileOpen) { oldOut = Msg::getOutStream(); Msg::open_file(filename, std::ios::out); fileOpen = true; @@ -505,20 +501,20 @@ namespace AMDiS { instanceCounters.end(), orderInstanceCount()); MSG("MemoryMonitor %s - statistics since creation:\n", name.c_str()); - for(it = instanceCounters.begin(); it != instanceCounters.end(); it++) { - if((*it)->getInstanceCount() != 0) { + for (it = instanceCounters.begin(); it != instanceCounters.end(); it++) { + if ((*it)->getInstanceCount() != 0) { MSG("%s : %d instance", (*it)->getTypeName().c_str(), static_cast<int>((*it)->getInstanceCount())); - if(static_cast<int>((*it)->getInstanceCount()) > 1) + if (static_cast<int>((*it)->getInstanceCount()) > 1) Msg::print("s"); MSG("\n"); } } - if(filename) { + if (filename) { Msg::change_out(oldOut); } - }; + } /** \brief * Adds a InstanceCounter to \ref instanceCounters. Used by MemoryManagerBase @@ -526,7 +522,7 @@ namespace AMDiS { */ inline void addInstanceCounter(InstanceCounterBase* counter) { instanceCounters.push_back(counter); - }; + } protected: /** \brief @@ -539,7 +535,7 @@ namespace AMDiS { public: bool operator()(InstanceCounterBase *a, InstanceCounterBase *b) { return (a->getInstanceCount() > b->getInstanceCount()); - }; + } }; protected: @@ -572,11 +568,12 @@ namespace AMDiS { singleton->instanceCount = 0; memoryManagers.push_back(singleton); std::vector<MemoryMonitor*>::iterator it; - for(it = memoryMonitors.begin(); it != memoryMonitors.end(); it++) { + for (it = memoryMonitors.begin(); it != memoryMonitors.end(); it++) { (*it)->addInstanceCounter(new InstanceCounter<T>); } } +#if 0 /** \brief * If MEMORY_MANAGED(T) is called in the public declaration of class T * the operators new, delete, new[], and delete[] are overloaded: @@ -586,32 +583,30 @@ namespace AMDiS { * about the file name and line number are given to the new operators which * are printed if \ref MemoryManager<T>::printInfo is true. */ -#if 0 #define MEMORY_MANAGED(className) \ void *operator new(size_t s) \ { \ return MemoryManager<className>::getMemory(s, NULL, 0); \ - }; \ - void *operator new(size_t s, const char *filename, int line) \ - { \ - return MemoryManager<className>::getMemory(s, filename, line); \ - }; \ - void operator delete(void *mem, size_t s) \ - { MemoryManager<className>::freeMemory(static_cast<className*>(mem), s);}; \ - void *operator new[](size_t s, const char *filename=NULL, int line=0) \ - { \ - return MemoryManager<className>::getMemory(s, filename, line); \ - }; \ - void operator delete[](void *mem, size_t s) \ - { MemoryManager<className>::freeMemory(static_cast<className*>(mem), s); }; \ - void *operator new(size_t, void *ptr) { \ - return ptr; \ - } + } \ + void *operator new(size_t s, const char *filename, int line) \ + { \ + return MemoryManager<className>::getMemory(s, filename, line); \ + } \ + void operator delete(void *mem, size_t s) \ + { MemoryManager<className>::freeMemory(static_cast<className*>(mem), s);}; \ + void *operator new[](size_t s, const char *filename=NULL, int line=0) \ + { \ + return MemoryManager<className>::getMemory(s, filename, line); \ + } \ + void operator delete[](void *mem, size_t s) \ + { MemoryManager<className>::freeMemory(static_cast<className*>(mem), s); }; \ + void *operator new(size_t, void *ptr) { \ + return ptr; \ + } /** \brief * Calls the new operator with additional file name and line number information */ - //#define NEW new (__FILE__,__LINE__) // leads to internal compiler error in some cases #define NEW new /** \brief @@ -636,13 +631,13 @@ namespace AMDiS { #endif + // use these macros to deactivate memory management #define MEMORY_MANAGED(className) ; #define NEW new #define DELETE delete #define GET_MEMORY(typename, number) new typename[number] #define FREE_MEMORY(ptr, typename, number) delete [] ptr - } #endif // AMDIS_MEMORYMANAGER_H diff --git a/AMDiS/src/ProblemScal.cc b/AMDiS/src/ProblemScal.cc index 957dc59aa7dba174d8b0bc99e002ae2751d0d1e1..06fc4606ff7f4f43b8d824a2fa63b0a1d6866d60 100644 --- a/AMDiS/src/ProblemScal.cc +++ b/AMDiS/src/ProblemScal.cc @@ -655,7 +655,7 @@ namespace AMDiS { traversePtr_->getRHS()->assemble(1.0, elInfo, bound); if (traversePtr_->getBoundUsed()) { - FREE_MEMORY(bound, BoundaryTyppe, traversePtr_->getFESpace()->getBasisFcts()->getNumber()); + FREE_MEMORY(bound, BoundaryType, traversePtr_->getFESpace()->getBasisFcts()->getNumber()); } return 0; diff --git a/AMDiS/src/ProblemVec.cc b/AMDiS/src/ProblemVec.cc index bdfb390bcb61762e962d07c3ef8769ea18b9346f..b4d9ee905c00d4bcf79f1f75a74a3539d27054c8 100644 --- a/AMDiS/src/ProblemVec.cc +++ b/AMDiS/src/ProblemVec.cc @@ -51,6 +51,18 @@ namespace AMDiS { componentMeshes = adoptProblem->componentMeshes; refinementManager_ = adoptProblem->refinementManager_; coarseningManager_ = adoptProblem->coarseningManager_; + + // If the adopt problem has fewer components than this problem, but only one + // mesh for all component, than scal up the componentMeshes array. + if (adoptProblem->getNumComponents() < numComponents_) { + TEST_EXIT(meshes_.size() == 1)("Daran muss ich noch arbeiten!\n"); + + componentMeshes_.resize(numComponents_); + for (int i = adoptProblem->getNumComponents(); i < numComponents_; i++) { + componentMeshes_[i] = componentMeshes_[0]; + } + } + } } @@ -69,6 +81,18 @@ namespace AMDiS { (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) { feSpaces = adoptProblem->getFESpaces(); componentSpaces = adoptProblem->componentSpaces; + + // If the adopt problem has fewer components than this problem, but only one + // fe space for all component, than scal up the componentSpaces array. + if (adoptProblem->getNumComponents() < numComponents_) { + TEST_EXIT(feSpaces_.size() == 1)("Daran muss ich noch arbeiten!\n"); + + componentSpaces_.resize(numComponents_); + for (int i = adoptProblem->getNumComponents(); i < numComponents_; i++) { + componentSpaces_[i] = componentSpaces_[0]; + } + } + } } diff --git a/AMDiS/src/SolutionDataStorage.hh b/AMDiS/src/SolutionDataStorage.hh index 62fcb18eaefbb44e55b8deeef1d68317f60fe86c..41586dfec9c82ca97aa8e9faf3f354a8bd876791 100644 --- a/AMDiS/src/SolutionDataStorage.hh +++ b/AMDiS/src/SolutionDataStorage.hh @@ -52,6 +52,8 @@ namespace AMDiS { solutions.push_back(solution); timestamps.push_back(timestamp); + std::cout << "STACK SIZE = " << solutions.size() << std::endl; + lastPos++; // memoryUsage += solution->calcMemoryUsage(); }