Commit 0735b5ba authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Small bugfix for composed problems with different number of components

parent 2c8d6db8
...@@ -10,7 +10,7 @@ namespace AMDiS { ...@@ -10,7 +10,7 @@ namespace AMDiS {
void MemoryManagerBase::addMemoryMonitor(MemoryMonitor* monitor) { void MemoryManagerBase::addMemoryMonitor(MemoryMonitor* monitor) {
memoryMonitors.push_back(monitor); memoryMonitors.push_back(monitor);
std::vector<MemoryManagerBase*>::iterator it; 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()); monitor->addInstanceCounter((*it)->newInstanceCounter());
} }
} }
...@@ -18,7 +18,7 @@ namespace AMDiS { ...@@ -18,7 +18,7 @@ namespace AMDiS {
void MemoryManagerBase::removeMemoryMonitor(MemoryMonitor* monitor) { void MemoryManagerBase::removeMemoryMonitor(MemoryMonitor* monitor) {
std::vector<MemoryMonitor*>::iterator it; std::vector<MemoryMonitor*>::iterator it;
it = find(memoryMonitors.begin(), memoryMonitors.end(), monitor); it = find(memoryMonitors.begin(), memoryMonitors.end(), monitor);
if(it != memoryMonitors.end()) { if (it != memoryMonitors.end()) {
memoryMonitors.erase(it); memoryMonitors.erase(it);
} }
} }
......
...@@ -69,7 +69,7 @@ namespace AMDiS { ...@@ -69,7 +69,7 @@ namespace AMDiS {
/** \brief /** \brief
* Destructor does nothing * Destructor does nothing
*/ */
virtual ~MemoryManagerBase() {}; virtual ~MemoryManagerBase() {}
/** \brief /** \brief
* Prints the number of currently allocated bytes (\ref byteCount) and for * Prints the number of currently allocated bytes (\ref byteCount) and for
...@@ -88,8 +88,8 @@ namespace AMDiS { ...@@ -88,8 +88,8 @@ namespace AMDiS {
MSG("memory statistics:\n"); MSG("memory statistics:\n");
MSG("==================\n"); MSG("==================\n");
MSG("byte count: %ld\n", byteCount); MSG("byte count: %ld\n", byteCount);
for(it = memoryManagers.begin(); it != memoryManagers.end(); it++) { for (it = memoryManagers.begin(); it != memoryManagers.end(); it++) {
if((*it)->instanceCount != 0) { if ((*it)->instanceCount != 0) {
MSG("%s, id = %ld : %ld instance%s", MSG("%s, id = %ld : %ld instance%s",
(*it)->getName().c_str(), (*it)->typeId, (*it)->instanceCount,((*it)->instanceCount > 1)?pl:sg); (*it)->getName().c_str(), (*it)->typeId, (*it)->instanceCount,((*it)->instanceCount > 1)?pl:sg);
// if((*it)->instanceCount > 1) // if((*it)->instanceCount > 1)
...@@ -98,7 +98,7 @@ namespace AMDiS { ...@@ -98,7 +98,7 @@ namespace AMDiS {
} }
} }
MSG("================================================================\n"); MSG("================================================================\n");
}; }
/** \brief /** \brief
* Must be overriden for concrete MemoryManagers. Returns the name of * Must be overriden for concrete MemoryManagers. Returns the name of
...@@ -112,14 +112,14 @@ namespace AMDiS { ...@@ -112,14 +112,14 @@ namespace AMDiS {
*/ */
inline unsigned long int getInstanceCount() { inline unsigned long int getInstanceCount() {
return instanceCount; return instanceCount;
}; }
/** \brief /** \brief
* Returns the number of currently allocated bytes (\ref typedByteCount). * Returns the number of currently allocated bytes (\ref typedByteCount).
*/ */
inline unsigned long int getTypedByteCount() { inline unsigned long int getTypedByteCount() {
return typedByteCount; return typedByteCount;
}; }
/** \brief /** \brief
* Returns a new InstanceCounter for concrete type * Returns a new InstanceCounter for concrete type
...@@ -148,7 +148,7 @@ namespace AMDiS { ...@@ -148,7 +148,7 @@ namespace AMDiS {
public: public:
bool operator()(MemoryManagerBase *a, MemoryManagerBase *b) { bool operator()(MemoryManagerBase *a, MemoryManagerBase *b) {
return (a->getInstanceCount() > b->getInstanceCount()); return (a->getInstanceCount() > b->getInstanceCount());
}; }
}; };
protected: protected:
...@@ -231,7 +231,7 @@ namespace AMDiS { ...@@ -231,7 +231,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor * Constructor
*/ */
MemoryManager() {}; MemoryManager() {}
public: public:
/** \brief /** \brief
...@@ -269,7 +269,7 @@ namespace AMDiS { ...@@ -269,7 +269,7 @@ namespace AMDiS {
preallocatable ? preallocatable ?
reinterpret_cast<T*>(MemoryPool::getMemory(s)) : reinterpret_cast<T*>(MemoryPool::getMemory(s)) :
reinterpret_cast<T*>(new char[s]); reinterpret_cast<T*>(new char[s]);
}; }
/** \brief /** \brief
* Frees memory which was allocated by \ref getMemory(). If \ref printInfo * Frees memory which was allocated by \ref getMemory(). If \ref printInfo
...@@ -289,54 +289,49 @@ namespace AMDiS { ...@@ -289,54 +289,49 @@ namespace AMDiS {
preallocatable ? preallocatable ?
MemoryPool::freeMemory(mem, s) : MemoryPool::freeMemory(mem, s) :
delete [] (reinterpret_cast<char*>(mem)); delete [] (reinterpret_cast<char*>(mem));
}; }
/** \brief /** \brief
* Returns name of T by demangle the mangled typeid of T. * Returns name of T by demangle the mangled typeid of T.
*/ */
inline std::string getName() { 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(); return typeid(T).name();
}; }
/** \brief /** \brief
* Sets \ref preallocatable * Sets \ref preallocatable
*/ */
static void setPreallocatable(bool prealloc) { static void setPreallocatable(bool prealloc) {
preallocatable = prealloc; preallocatable = prealloc;
}; }
/** \brief /** \brief
* Sets \ref printInfo * Sets \ref printInfo
*/ */
static void setPrintInfo(bool p) { static void setPrintInfo(bool p) {
printInfo = p; printInfo = p;
}; }
/** \brief /** \brief
* Returns \ref printInfo * Returns \ref printInfo
*/ */
static bool getPrintInfo() { return printInfo; }; static bool getPrintInfo() {
return printInfo;
}
/** \brief /** \brief
* Returns the pointer to the \ref singleton instance of MemoryManager<T> * Returns the pointer to the \ref singleton instance of MemoryManager<T>
*/ */
static MemoryManager<T>* getSingleton() { return singleton; }; static MemoryManager<T>* getSingleton() {
return singleton;
}
/** \brief /** \brief
* Implementation of \ref MemoryManagerBase::newInstanceCounter() * Implementation of \ref MemoryManagerBase::newInstanceCounter()
*/ */
InstanceCounterBase* newInstanceCounter() { InstanceCounterBase* newInstanceCounter() {
return new InstanceCounter<T>; return new InstanceCounter<T>;
}; }
protected: protected:
/** \brief /** \brief
...@@ -417,7 +412,7 @@ namespace AMDiS { ...@@ -417,7 +412,7 @@ namespace AMDiS {
*/ */
InstanceCounter() InstanceCounter()
: oldInstanceCount(MemoryManager<T>::getSingleton()->getInstanceCount()) : oldInstanceCount(MemoryManager<T>::getSingleton()->getInstanceCount())
{}; {}
/** \brief /** \brief
* Sets \ref oldInstanceCount to the current number of instances in * Sets \ref oldInstanceCount to the current number of instances in
...@@ -425,7 +420,7 @@ namespace AMDiS { ...@@ -425,7 +420,7 @@ namespace AMDiS {
*/ */
inline void reset() { inline void reset() {
oldInstanceCount = MemoryManager<T>::getSingleton()->getInstanceCount(); oldInstanceCount = MemoryManager<T>::getSingleton()->getInstanceCount();
}; }
/** \brief /** \brief
* Returns the difference between the current instanceCount and * Returns the difference between the current instanceCount and
...@@ -434,14 +429,14 @@ namespace AMDiS { ...@@ -434,14 +429,14 @@ namespace AMDiS {
long int getInstanceCount() { long int getInstanceCount() {
return (MemoryManager<T>::getSingleton()->getInstanceCount() - return (MemoryManager<T>::getSingleton()->getInstanceCount() -
oldInstanceCount); oldInstanceCount);
}; }
/** \brief /** \brief
* Returns the name of T. Calls MemoryManager<T>::getName() * Returns the name of T. Calls MemoryManager<T>::getName()
*/ */
std::string getTypeName() { std::string getTypeName() {
return MemoryManager<T>::getSingleton()->getName(); return MemoryManager<T>::getSingleton()->getName();
}; }
protected: protected:
/** \brief /** \brief
...@@ -473,10 +468,11 @@ namespace AMDiS { ...@@ -473,10 +468,11 @@ namespace AMDiS {
* Constructor. Registers itself with MemoryMonitorBase. * Constructor. Registers itself with MemoryMonitorBase.
*/ */
MemoryMonitor(const char *name_, const char *filename_=NULL) MemoryMonitor(const char *name_, const char *filename_=NULL)
: name(name_), filename(filename_) : name(name_),
filename(filename_)
{ {
MemoryManagerBase::addMemoryMonitor(this); MemoryManagerBase::addMemoryMonitor(this);
}; }
/** \brief /** \brief
* Destructor. Prints statistics and deregisters itself with * Destructor. Prints statistics and deregisters itself with
...@@ -485,7 +481,7 @@ namespace AMDiS { ...@@ -485,7 +481,7 @@ namespace AMDiS {
~MemoryMonitor() { ~MemoryMonitor() {
printStatistics(); printStatistics();
MemoryManagerBase::removeMemoryMonitor(this); MemoryManagerBase::removeMemoryMonitor(this);
}; }
/** \brief /** \brief
* Prints a statistic for every data type with instanceCount - * Prints a statistic for every data type with instanceCount -
...@@ -495,7 +491,7 @@ namespace AMDiS { ...@@ -495,7 +491,7 @@ namespace AMDiS {
FUNCNAME("MemoryMonitor::printStatistics()"); FUNCNAME("MemoryMonitor::printStatistics()");
std::ostream *oldOut; std::ostream *oldOut;
static bool fileOpen = false; static bool fileOpen = false;
if(filename && !fileOpen) { if (filename && !fileOpen) {
oldOut = Msg::getOutStream(); oldOut = Msg::getOutStream();
Msg::open_file(filename, std::ios::out); Msg::open_file(filename, std::ios::out);
fileOpen = true; fileOpen = true;
...@@ -505,20 +501,20 @@ namespace AMDiS { ...@@ -505,20 +501,20 @@ namespace AMDiS {
instanceCounters.end(), instanceCounters.end(),
orderInstanceCount()); orderInstanceCount());
MSG("MemoryMonitor %s - statistics since creation:\n", name.c_str()); MSG("MemoryMonitor %s - statistics since creation:\n", name.c_str());
for(it = instanceCounters.begin(); it != instanceCounters.end(); it++) { for (it = instanceCounters.begin(); it != instanceCounters.end(); it++) {
if((*it)->getInstanceCount() != 0) { if ((*it)->getInstanceCount() != 0) {
MSG("%s : %d instance", MSG("%s : %d instance",
(*it)->getTypeName().c_str(), (*it)->getTypeName().c_str(),
static_cast<int>((*it)->getInstanceCount())); static_cast<int>((*it)->getInstanceCount()));
if(static_cast<int>((*it)->getInstanceCount()) > 1) if (static_cast<int>((*it)->getInstanceCount()) > 1)
Msg::print("s"); Msg::print("s");
MSG("\n"); MSG("\n");
} }
} }
if(filename) { if (filename) {
Msg::change_out(oldOut); Msg::change_out(oldOut);
} }
}; }
/** \brief /** \brief
* Adds a InstanceCounter to \ref instanceCounters. Used by MemoryManagerBase * Adds a InstanceCounter to \ref instanceCounters. Used by MemoryManagerBase
...@@ -526,7 +522,7 @@ namespace AMDiS { ...@@ -526,7 +522,7 @@ namespace AMDiS {
*/ */
inline void addInstanceCounter(InstanceCounterBase* counter) { inline void addInstanceCounter(InstanceCounterBase* counter) {
instanceCounters.push_back(counter); instanceCounters.push_back(counter);
}; }
protected: protected:
/** \brief /** \brief
...@@ -539,7 +535,7 @@ namespace AMDiS { ...@@ -539,7 +535,7 @@ namespace AMDiS {
public: public:
bool operator()(InstanceCounterBase *a, InstanceCounterBase *b) { bool operator()(InstanceCounterBase *a, InstanceCounterBase *b) {
return (a->getInstanceCount() > b->getInstanceCount()); return (a->getInstanceCount() > b->getInstanceCount());
}; }
}; };
protected: protected:
...@@ -572,11 +568,12 @@ namespace AMDiS { ...@@ -572,11 +568,12 @@ namespace AMDiS {
singleton->instanceCount = 0; singleton->instanceCount = 0;
memoryManagers.push_back(singleton); memoryManagers.push_back(singleton);
std::vector<MemoryMonitor*>::iterator it; 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>); (*it)->addInstanceCounter(new InstanceCounter<T>);
} }
} }
#if 0
/** \brief /** \brief
* If MEMORY_MANAGED(T) is called in the public declaration of class T * If MEMORY_MANAGED(T) is called in the public declaration of class T
* the operators new, delete, new[], and delete[] are overloaded: * the operators new, delete, new[], and delete[] are overloaded:
...@@ -586,32 +583,30 @@ namespace AMDiS { ...@@ -586,32 +583,30 @@ namespace AMDiS {
* about the file name and line number are given to the new operators which * about the file name and line number are given to the new operators which
* are printed if \ref MemoryManager<T>::printInfo is true. * are printed if \ref MemoryManager<T>::printInfo is true.
*/ */
#if 0
#define MEMORY_MANAGED(className) \ #define MEMORY_MANAGED(className) \
void *operator new(size_t s) \ void *operator new(size_t s) \
{ \ { \
return MemoryManager<className>::getMemory(s, NULL, 0); \ return MemoryManager<className>::getMemory(s, NULL, 0); \
}; \ } \
void *operator new(size_t s, const char *filename, int line) \ void *operator new(size_t s, const char *filename, int line) \
{ \ { \
return MemoryManager<className>::getMemory(s, filename, line); \ return MemoryManager<className>::getMemory(s, filename, line); \
}; \ } \
void operator delete(void *mem, size_t s) \ void operator delete(void *mem, size_t s) \
{ MemoryManager<className>::freeMemory(static_cast<className*>(mem), s);}; \ { MemoryManager<className>::freeMemory(static_cast<className*>(mem), s);}; \
void *operator new[](size_t s, const char *filename=NULL, int line=0) \ void *operator new[](size_t s, const char *filename=NULL, int line=0) \
{ \ { \
return MemoryManager<className>::getMemory(s, filename, line); \ return MemoryManager<className>::getMemory(s, filename, line); \
}; \ } \
void operator delete[](void *mem, size_t s) \ void operator delete[](void *mem, size_t s) \
{ MemoryManager<className>::freeMemory(static_cast<className*>(mem), s); }; \ { MemoryManager<className>::freeMemory(static_cast<className*>(mem), s); }; \
void *operator new(size_t, void *ptr) { \ void *operator new(size_t, void *ptr) { \
return ptr; \ return ptr; \
} }
/** \brief /** \brief
* Calls the new operator with additional file name and line number information * 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 #define NEW new
/** \brief /** \brief
...@@ -636,13 +631,13 @@ namespace AMDiS { ...@@ -636,13 +631,13 @@ namespace AMDiS {
#endif #endif
// use these macros to deactivate memory management // use these macros to deactivate memory management
#define MEMORY_MANAGED(className) ; #define MEMORY_MANAGED(className) ;
#define NEW new #define NEW new
#define DELETE delete #define DELETE delete
#define GET_MEMORY(typename, number) new typename[number] #define GET_MEMORY(typename, number) new typename[number]
#define FREE_MEMORY(ptr, typename, number) delete [] ptr #define FREE_MEMORY(ptr, typename, number) delete [] ptr
} }
#endif // AMDIS_MEMORYMANAGER_H #endif // AMDIS_MEMORYMANAGER_H
...@@ -655,7 +655,7 @@ namespace AMDiS { ...@@ -655,7 +655,7 @@ namespace AMDiS {
traversePtr_->getRHS()->assemble(1.0, elInfo, bound); traversePtr_->getRHS()->assemble(1.0, elInfo, bound);
if (traversePtr_->getBoundUsed()) { if (traversePtr_->getBoundUsed()) {
FREE_MEMORY(bound, BoundaryTyppe, traversePtr_->getFESpace()->getBasisFcts()->getNumber()); FREE_MEMORY(bound, BoundaryType, traversePtr_->getFESpace()->getBasisFcts()->getNumber());
} }
return 0; return 0;
......
...@@ -51,6 +51,18 @@ namespace AMDiS { ...@@ -51,6 +51,18 @@ namespace AMDiS {
componentMeshes = adoptProblem->componentMeshes; componentMeshes = adoptProblem->componentMeshes;
refinementManager_ = adoptProblem->refinementManager_; refinementManager_ = adoptProblem->refinementManager_;
coarseningManager_ = adoptProblem->coarseningManager_; 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 { ...@@ -69,6 +81,18 @@ namespace AMDiS {
(adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) { (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) {
feSpaces = adoptProblem->getFESpaces(); feSpaces = adoptProblem->getFESpaces();
componentSpaces = adoptProblem->componentSpaces; 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];
}
}
} }
} }
......
...@@ -52,6 +52,8 @@ namespace AMDiS { ...@@ -52,6 +52,8 @@ namespace AMDiS {
solutions.push_back(solution); solutions.push_back(solution);
timestamps.push_back(timestamp); timestamps.push_back(timestamp);
std::cout << "STACK SIZE = " << solutions.size() << std::endl;
lastPos++; lastPos++;
// memoryUsage += solution->calcMemoryUsage(); // memoryUsage += solution->calcMemoryUsage();
} }
......
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