diff --git a/AMDiS/src/ElementData.cc b/AMDiS/src/ElementData.cc index e0253c5ad103a7dae02d92bb2c67c8bc682b8fb8..892a7e3e33e8d38a4a8512c56b148cef4c697cbc 100644 --- a/AMDiS/src/ElementData.cc +++ b/AMDiS/src/ElementData.cc @@ -7,32 +7,31 @@ namespace AMDiS { Element* otherChild, int elTypeParent) { - if (decorated_) { - PartitionElementData* ped=NULL; - ped=dynamic_cast<PartitionElementData*> (thisChild->getElementData(PARTITION_ED)); - ped=NULL; - ped=dynamic_cast<PartitionElementData*> (otherChild->getElementData(PARTITION_ED)); - - ped=NULL; - ped=dynamic_cast<PartitionElementData*> (parent->getElementData(PARTITION_ED)); - - decorated_->coarsenElementData(parent, thisChild, otherChild, elTypeParent); - delete decorated_; - decorated_ = NULL; + if (decorated) { + PartitionElementData* ped = NULL; + ped = dynamic_cast<PartitionElementData*>(thisChild->getElementData(PARTITION_ED)); + ped = NULL; + ped = dynamic_cast<PartitionElementData*>(otherChild->getElementData(PARTITION_ED)); + ped = NULL; + ped = dynamic_cast<PartitionElementData*> (parent->getElementData(PARTITION_ED)); + + decorated->coarsenElementData(parent, thisChild, otherChild, elTypeParent); + delete decorated; + decorated = NULL; } } bool ElementData::deleteDecorated(int typeID) { - if (decorated_) { - if (decorated_->isOfType(typeID)) { - ElementData *tmp = decorated_; - decorated_ = decorated_->decorated_; + if (decorated) { + if (decorated->isOfType(typeID)) { + ElementData *tmp = decorated; + decorated = decorated->decorated; delete tmp; tmp = NULL; return true; } else { - return decorated_->deleteDecorated(typeID); + return decorated->deleteDecorated(typeID); } } return false; @@ -40,9 +39,9 @@ namespace AMDiS { void ElementData::deleteDecorated() { - if (decorated_) { - decorated_->deleteDecorated(); - delete decorated_; + if (decorated) { + decorated->deleteDecorated(); + delete decorated; } } @@ -53,10 +52,10 @@ namespace AMDiS { void ElementData::serialize(std::ostream& out) { std::string decoratedType; - if (decorated_) { - decoratedType = decorated_->getTypeName(); + if (decorated) { + decoratedType = decorated->getTypeName(); out << decoratedType << "\n"; - decorated_->serialize(out); + decorated->serialize(out); } else { out << "NULL\n"; } @@ -64,16 +63,16 @@ namespace AMDiS { void ElementData::deserialize(std::istream& in) { - TEST_EXIT(decorated_ == NULL) + TEST_EXIT(decorated == NULL) ("there are already decorated element data\n"); std::string decoratedType; in >> decoratedType; in.get(); if (decoratedType != "NULL") { - decorated_ = CreatorMap<ElementData>::getCreator(decoratedType)->create(); - decorated_->deserialize(in); + decorated = CreatorMap<ElementData>::getCreator(decoratedType)->create(); + decorated->deserialize(in); } else { - decorated_ = NULL; + decorated = NULL; } } diff --git a/AMDiS/src/ElementData.h b/AMDiS/src/ElementData.h index 8284951f0c6524e89c840a1d33a8a2995a91a1a6..85c3e2c07e36e9c97543d428dfe236f89767a49c 100644 --- a/AMDiS/src/ElementData.h +++ b/AMDiS/src/ElementData.h @@ -43,8 +43,8 @@ namespace AMDiS { { public: /// constructor - ElementData(ElementData *decorated = NULL) - : decorated_(decorated) + ElementData(ElementData *dec = NULL) + : decorated(dec) {} /// destructor @@ -56,14 +56,14 @@ namespace AMDiS { Element* child2, int elType) { - if (decorated_) { + if (decorated) { bool remove = - decorated_->refineElementData(parent, child1, child2, elType); + decorated->refineElementData(parent, child1, child2, elType); if (remove) { - ElementData *tmp = decorated_->decorated_; - delete decorated_; - decorated_ = tmp; + ElementData *tmp = decorated->decorated; + delete decorated; + decorated = tmp; } } return false; @@ -78,8 +78,8 @@ namespace AMDiS { /// Returns a copy of this ElementData object including all decorated data. virtual ElementData *clone() const { - if (decorated_) - return decorated_->clone(); + if (decorated) + return decorated->clone(); return NULL; } @@ -108,32 +108,32 @@ namespace AMDiS { if (this->isOfType(typeID)) { return this; } else { - if (decorated_) - return decorated_->getElementData(typeID); + if (decorated) + return decorated->getElementData(typeID); } return NULL; } inline ElementData *getDecorated(int typeID) { - if (decorated_) - return decorated_->getElementData(typeID); + if (decorated) + return decorated->getElementData(typeID); return NULL; } /** \ref - * Search the \ref decorated_ chain for a specific type ID, and delets + * Search the \ref decorated chain for a specific type ID, and delets * this entry. */ bool deleteDecorated(int typeID); - /// Delets the whole \ref decorated_ chain. + /// Delets the whole \ref decorated chain. void deleteDecorated(); inline ElementData *getDecorated() { - return decorated_; + return decorated; } inline void setDecorated(ElementData *d) @@ -142,12 +142,12 @@ namespace AMDiS { if (d != NULL) std::cout << "leafdata decorated with nonzero" << std::endl; - decorated_ = d; + decorated = d; } protected: /// Pointer to next ElementData object in the chain of responsibility. - ElementData *decorated_; + ElementData *decorated; }; } diff --git a/AMDiS/src/ElementRegion_ED.h b/AMDiS/src/ElementRegion_ED.h index 9be6dee5ccb08b14df7d8d738249a155f795b4a2..60b6b71a744cf8d30cbf40b35913649b397a561d 100644 --- a/AMDiS/src/ElementRegion_ED.h +++ b/AMDiS/src/ElementRegion_ED.h @@ -17,10 +17,10 @@ // == == // ============================================================================ -/** \file ElementRegion_ED.h */ +/** \file ElementRegionED.h */ -#ifndef AMDIS_ELEMENTREGION_ED_H -#define AMDIS_ELEMENTREGION_ED_H +#ifndef AMDIS_ELEMENTREGIONED_H +#define AMDIS_ELEMENTREGIONED_H #include "ElementData.h" #include "FixVec.h" @@ -48,7 +48,7 @@ namespace AMDiS { ElementRegion_ED(ElementData *decorated = NULL) : ElementData(decorated), - region_(-1) + region(-1) {} bool refineElementData(Element* parent, @@ -61,11 +61,11 @@ namespace AMDiS { ElementRegion_ED *ep; ep = new ElementRegion_ED(child1->getElementData()); - ep->region_ = region_; + ep->region = region; child1->setElementData(ep); ep = new ElementRegion_ED(child2->getElementData()); - ep->region_ = region_; + ep->region = region; child2->setElementData(ep); return false; @@ -74,14 +74,14 @@ namespace AMDiS { ElementData *clone() const { ElementRegion_ED *newObj = new ElementRegion_ED; - newObj->region_ = region_; - newObj->decorated_ = ElementData::clone(); + newObj->region = region; + newObj->decorated = ElementData::clone(); return newObj; } inline std::string getTypeName() const { - return "ElementRegion_ED"; + return "ElementRegionED"; } inline const int getTypeID() const @@ -92,27 +92,27 @@ namespace AMDiS { void serialize(std::ostream& out) { ElementData::serialize(out); - out.write(reinterpret_cast<const char*>(®ion_), sizeof(int)); + out.write(reinterpret_cast<const char*>(®ion), sizeof(int)); } void deserialize(std::istream& in) { ElementData::deserialize(in); - in.read(reinterpret_cast<char*>(®ion_), sizeof(int)); + in.read(reinterpret_cast<char*>(®ion), sizeof(int)); } - inline void setRegion(int region) + inline void setRegion(int r) { - region_ = region; + region = r; } inline int getRegion() const { - return region_; + return region; } protected: - int region_; + int region; }; } diff --git a/AMDiS/src/LeafData.h b/AMDiS/src/LeafData.h index 4f30374088460af97fb37b45cccd63f78301fe01..ded8a065eedd6f2e8c0af6492a64366958c02f25 100644 --- a/AMDiS/src/LeafData.h +++ b/AMDiS/src/LeafData.h @@ -102,7 +102,7 @@ namespace AMDiS { newObj->errorEstimate = errorEstimate; // clone decorated element data (=> deep copy) - newObj->decorated_ = ElementData::clone(); + newObj->decorated = ElementData::clone(); // return the clone return newObj; @@ -193,7 +193,7 @@ namespace AMDiS { newObj->errorEstimate = errorEstimate; // clone decorated element data (=> deep copy) - newObj->decorated_ = ElementData::clone(); + newObj->decorated = ElementData::clone(); // return the clone return newObj; @@ -298,7 +298,7 @@ namespace AMDiS { LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL); // clone decorated element data (=> deep copy) - newObj->decorated_ = ElementData::clone(); + newObj->decorated = ElementData::clone(); // return the clone return newObj; @@ -377,7 +377,7 @@ namespace AMDiS { newObj->coarseningError = coarseningError; // clone decorated leaf data (=> deep copy) - newObj->decorated_ = ElementData::clone(); + newObj->decorated = ElementData::clone(); // return the clone return newObj; @@ -547,7 +547,7 @@ namespace AMDiS { inline ElementData *clone() const { LeafDataPeriodic *newObj = new LeafDataPeriodic; - newObj->decorated_ = ElementData::clone(); + newObj->decorated = ElementData::clone(); return newObj; } diff --git a/AMDiS/src/ParallelDomainScal.cc b/AMDiS/src/ParallelDomainScal.cc index 4335aef95976fa835bfafa72c28e19412f5dc139..c837efedceaad4e9a29857f5b1ec2523c891b7f3 100644 --- a/AMDiS/src/ParallelDomainScal.cc +++ b/AMDiS/src/ParallelDomainScal.cc @@ -14,6 +14,12 @@ namespace AMDiS { probScal(problem) { info = problem->getInfo(); + + // Create parallel serialization file writer, if needed. + int writeSerialization = 0; + GET_PARAMETER(0, name + "->output->write serialization", "%d", &writeSerialization); + if (writeSerialization) + problem->getFileWriterList().push_back(new Serializer<ParallelDomainScal>(this)); } void ParallelDomainScal::initParallelization(AdaptInfo *adaptInfo) diff --git a/AMDiS/src/ParallelDomainScal.h b/AMDiS/src/ParallelDomainScal.h index 99f571a3155c0f8e295aedf92af565abf123052f..bb534f48ba57d85d0308cab9963ce22dcd74bfa6 100644 --- a/AMDiS/src/ParallelDomainScal.h +++ b/AMDiS/src/ParallelDomainScal.h @@ -23,6 +23,7 @@ #define AMDIS_PARALLELDOMAINSCAL_H #include "ParallelDomainBase.h" +#include "ProblemScal.h" namespace AMDiS { @@ -34,6 +35,20 @@ namespace AMDiS { void initParallelization(AdaptInfo *adaptInfo); + // Writes all data of this object to an output stream. + virtual void serialize(std::ostream &out) + { + probScal->serialize(out); + ParallelDomainBase::serialize(out); + } + + // Reads the object data from an input stream. + virtual void deserialize(std::istream &in) + { + probScal->deserialize(in); + ParallelDomainBase::deserialize(in); + } + protected: /// Starts the solution of the linear system using Petsc. void solve(); diff --git a/AMDiS/src/ParallelDomainVec.cc b/AMDiS/src/ParallelDomainVec.cc index c3ff8b5cdd2a16a507925de7119a64b1c4d7c2e3..e4c2e818ecbbe51644a024f678bed3800609809b 100644 --- a/AMDiS/src/ParallelDomainVec.cc +++ b/AMDiS/src/ParallelDomainVec.cc @@ -2,6 +2,7 @@ #include "ProblemVec.h" #include "ProblemInstat.h" #include "SystemVector.h" +#include "Serializer.h" namespace AMDiS { @@ -18,10 +19,18 @@ namespace AMDiS { info = probVec->getInfo(); nComponents = probVec->getNumComponents(); + // Test if all fe spaces are equal. Yet, different fe spaces are not supported for + // domain parallelization. const FiniteElemSpace *fe = probVec->getFESpace(0); for (int i = 0; i < nComponents; i++) TEST_EXIT(fe == probVec->getFESpace(i)) ("Parallelization does not supported different FE spaces!\n"); + + // Create parallel serialization file writer, if needed. + int writeSerialization = 0; + GET_PARAMETER(0, name + "->output->write serialization", "%d", &writeSerialization); + if (writeSerialization) + problem->getFileWriterList().push_back(new Serializer<ParallelDomainVec>(this)); } diff --git a/AMDiS/src/ParallelDomainVec.h b/AMDiS/src/ParallelDomainVec.h index bea1cf9ab12a737f564c3fce97130feee15c805c..4d6a7f4fde4d4f42f777443e762d1804c2177c9f 100644 --- a/AMDiS/src/ParallelDomainVec.h +++ b/AMDiS/src/ParallelDomainVec.h @@ -42,6 +42,20 @@ namespace AMDiS { synchVectors(*(probVec->getSolution())); } + // Writes all data of this object to an output stream. + virtual void serialize(std::ostream &out) + { + probVec->serialize(out); + ParallelDomainBase::serialize(out); + } + + // Reads the object data from an input stream. + virtual void deserialize(std::istream &in) + { + probVec->deserialize(in); + ParallelDomainBase::deserialize(in); + } + protected: /// Starts the solution of the linear system using Petsc. void solve(); diff --git a/AMDiS/src/PartitionElementData.h b/AMDiS/src/PartitionElementData.h index 72fd10fc51837419999180e838a55134a5c31322..a3a85956e472351ac85a9b22105d48f3188b35a7 100644 --- a/AMDiS/src/PartitionElementData.h +++ b/AMDiS/src/PartitionElementData.h @@ -40,16 +40,18 @@ namespace AMDiS { class PartitionElementData : public ElementData { public: - inline bool isOfType(int typeID) const { + inline bool isOfType(int typeID) const + { if (typeID == PARTITION_ED) - return true; + return true; return false; } class Creator : public CreatorInterface<ElementData> { public: - ElementData* create() { + ElementData* create() + { return new PartitionElementData; } }; @@ -68,10 +70,12 @@ namespace AMDiS { Element* child2, int elType) { - ElementData::refineElementData(parent, child1, child2, elType); + ElementData::refineElementData(parent, child1, child2, elType); - PartitionElementData *child1Data = new PartitionElementData(child1->getElementData()); - PartitionElementData *child2Data = new PartitionElementData(child2->getElementData()); + PartitionElementData *child1Data = + new PartitionElementData(child1->getElementData()); + PartitionElementData *child2Data = + new PartitionElementData(child2->getElementData()); child1Data->setPartitionStatus(status); child2Data->setPartitionStatus(status); child1Data->setLevel(level + 1); @@ -79,51 +83,58 @@ namespace AMDiS { child1->setElementData(child1Data); child2->setElementData(child2Data); return false; - }; + } - ElementData *clone() const { + ElementData *clone() const + { PartitionElementData *newObj = new PartitionElementData; - newObj->decorated_ = ElementData::clone(); + newObj->decorated = ElementData::clone(); return newObj; - }; + } - inline std::string getTypeName() const { + inline std::string getTypeName() const + { return "PartitionElementData"; - }; + } - inline const int getTypeID() const { + inline const int getTypeID() const + { return PARTITION_ED; - }; + } void serialize(std::ostream& out) { ElementData::serialize(out); out.write(reinterpret_cast<const char*>(&status), sizeof(PartitionStatus)); out.write(reinterpret_cast<const char*>(&level), sizeof(int)); - }; + } void deserialize(std::istream& in) { ElementData::deserialize(in); in.read(reinterpret_cast<char*>(&status), sizeof(PartitionStatus)); in.read(reinterpret_cast<char*>(&level), sizeof(int)); - }; + } - inline void setPartitionStatus(PartitionStatus status_) { + inline void setPartitionStatus(PartitionStatus status_) + { status = status_; - }; + } - inline PartitionStatus getPartitionStatus() { + inline PartitionStatus getPartitionStatus() + { return status; - }; + } - inline void setLevel(int level_) { - level = level_; - }; + inline void setLevel(int l) + { + level = l; + } - inline int getLevel() { + inline int getLevel() + { return level; - }; + } void descend(Element *element) { @@ -145,7 +156,7 @@ namespace AMDiS { child0Data->descend(child0); child1Data->descend(child1); } - }; + } protected: PartitionStatus status; diff --git a/AMDiS/src/ProblemScal.h b/AMDiS/src/ProblemScal.h index 2538decc8d8c02259a8da5519408e426621b5c9d..c4f28da7947b6acb357e34f9af46478cbf8a6323 100644 --- a/AMDiS/src/ProblemScal.h +++ b/AMDiS/src/ProblemScal.h @@ -186,7 +186,7 @@ namespace AMDiS { /// Adds robin boundary conditions. virtual void addRobinBC(BoundaryType type, - DOFVector<double> *n, + DOFVector<double> *n, DOFVector<double> *r); /// Adds Neumann boundary conditions. @@ -317,7 +317,7 @@ namespace AMDiS { virtual void deserialize(std::istream &in); /// Returns \ref fileWriters. - std::vector<FileWriterInterface*> getFileWriterList() + std::vector<FileWriterInterface*>& getFileWriterList() { return fileWriters; } diff --git a/AMDiS/src/Serializer.h b/AMDiS/src/Serializer.h index f2bf3f86dc727ae4a9bd298fd1f05f4bff817083..ffacbba63f37d3fbd281cfda77c69499a7c5245b 100644 --- a/AMDiS/src/Serializer.h +++ b/AMDiS/src/Serializer.h @@ -40,11 +40,17 @@ namespace AMDiS { tsModulo(1), timestepNumber(-1) { - GET_PARAMETER(0, problem->getName() + "->output->serialization filename", - &name); - GET_PARAMETER(0, problem->getName() + "->output->write every i-th timestep", + FUNCNAME("Serializer::Serializer()"); + + GET_PARAMETER(0, problem->getName() + "->output->serialization filename", &name); + GET_PARAMETER(0, problem->getName() + "->output->write every i-th timestep", "%d", &tsModulo); TEST_EXIT(name != "")("no filename\n"); + +#if HAVE_PARALLEL_DOMAIN_AMDIS + name += ".p"; + name += MPI::COMM_WORLD.Get_rank(); +#endif } virtual ~Serializer() {} diff --git a/AMDiS/src/SurfaceRegion_ED.h b/AMDiS/src/SurfaceRegion_ED.h index ca8f3246636930391725db87196ea1ca2792ae80..c861ad29580f35aa5a21e63607be8f3d4cb39613 100644 --- a/AMDiS/src/SurfaceRegion_ED.h +++ b/AMDiS/src/SurfaceRegion_ED.h @@ -30,7 +30,8 @@ namespace AMDiS { class SurfaceRegion_ED : public ElementData { public: - inline bool isOfType(int typeID) const { + inline bool isOfType(int typeID) const + { if (typeID == SURFACE_REGION) return true; return false; @@ -47,8 +48,8 @@ namespace AMDiS { SurfaceRegion_ED(ElementData *decorated = NULL) : ElementData(decorated), - side_(-1), - region_(-1) + side(-1), + region(-1) {} bool refineElementData(Element* parent, @@ -61,19 +62,19 @@ namespace AMDiS { int sideOfChild; SurfaceRegion_ED *surfaceRegion; - sideOfChild = parent->getSideOfChild(0, side_, elType); + sideOfChild = parent->getSideOfChild(0, side, elType); if (sideOfChild >= 0) { surfaceRegion = new SurfaceRegion_ED(child1->getElementData()); surfaceRegion->setSide(sideOfChild); - surfaceRegion->setRegion(region_); + surfaceRegion->setRegion(region); child1->setElementData(surfaceRegion); } - sideOfChild = parent->getSideOfChild(1, side_, elType); + sideOfChild = parent->getSideOfChild(1, side, elType); if (sideOfChild >= 0) { surfaceRegion = new SurfaceRegion_ED(child2->getElementData()); - surfaceRegion->side_ = sideOfChild; - surfaceRegion->region_ = region_; + surfaceRegion->side = sideOfChild; + surfaceRegion->region = region; child2->setElementData(surfaceRegion); } @@ -83,9 +84,9 @@ namespace AMDiS { ElementData *clone() const { SurfaceRegion_ED *newObj = new SurfaceRegion_ED; - newObj->side_ = side_; - newObj->region_ = region_; - newObj->decorated_ = ElementData::clone(); + newObj->side = side; + newObj->region = region; + newObj->decorated = ElementData::clone(); return newObj; } @@ -102,40 +103,40 @@ namespace AMDiS { void serialize(std::ostream& out) { ElementData::serialize(out); - out.write(reinterpret_cast<const char*>(&side_), sizeof(int)); - out.write(reinterpret_cast<const char*>(®ion_), sizeof(int)); + out.write(reinterpret_cast<const char*>(&side), sizeof(int)); + out.write(reinterpret_cast<const char*>(®ion), sizeof(int)); } void deserialize(std::istream& in) { ElementData::deserialize(in); - in.read(reinterpret_cast<char*>(&side_), sizeof(int)); - in.read(reinterpret_cast<char*>(®ion_), sizeof(int)); + in.read(reinterpret_cast<char*>(&side), sizeof(int)); + in.read(reinterpret_cast<char*>(®ion), sizeof(int)); } - inline void setSide(int side) + inline void setSide(int s) { - side_ = side; + side = s; } inline int getSide() const { - return side_; + return side; } - inline void setRegion(int region) + inline void setRegion(int r) { - region_ = region; + region = r; } inline int getRegion() const { - return region_; + return region; } protected: - int side_; - int region_; + int side; + int region; }; }