Commit 1a6ac357 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Modified Serializer for parallel serialization.

parent ded81b7f
...@@ -7,32 +7,31 @@ namespace AMDiS { ...@@ -7,32 +7,31 @@ namespace AMDiS {
Element* otherChild, Element* otherChild,
int elTypeParent) int elTypeParent)
{ {
if (decorated_) { if (decorated) {
PartitionElementData* ped=NULL; PartitionElementData* ped = NULL;
ped=dynamic_cast<PartitionElementData*> (thisChild->getElementData(PARTITION_ED)); ped = dynamic_cast<PartitionElementData*>(thisChild->getElementData(PARTITION_ED));
ped=NULL; ped = NULL;
ped=dynamic_cast<PartitionElementData*> (otherChild->getElementData(PARTITION_ED)); ped = dynamic_cast<PartitionElementData*>(otherChild->getElementData(PARTITION_ED));
ped = NULL;
ped=NULL; ped = dynamic_cast<PartitionElementData*> (parent->getElementData(PARTITION_ED));
ped=dynamic_cast<PartitionElementData*> (parent->getElementData(PARTITION_ED));
decorated->coarsenElementData(parent, thisChild, otherChild, elTypeParent);
decorated_->coarsenElementData(parent, thisChild, otherChild, elTypeParent); delete decorated;
delete decorated_; decorated = NULL;
decorated_ = NULL;
} }
} }
bool ElementData::deleteDecorated(int typeID) bool ElementData::deleteDecorated(int typeID)
{ {
if (decorated_) { if (decorated) {
if (decorated_->isOfType(typeID)) { if (decorated->isOfType(typeID)) {
ElementData *tmp = decorated_; ElementData *tmp = decorated;
decorated_ = decorated_->decorated_; decorated = decorated->decorated;
delete tmp; delete tmp;
tmp = NULL; tmp = NULL;
return true; return true;
} else { } else {
return decorated_->deleteDecorated(typeID); return decorated->deleteDecorated(typeID);
} }
} }
return false; return false;
...@@ -40,9 +39,9 @@ namespace AMDiS { ...@@ -40,9 +39,9 @@ namespace AMDiS {
void ElementData::deleteDecorated() void ElementData::deleteDecorated()
{ {
if (decorated_) { if (decorated) {
decorated_->deleteDecorated(); decorated->deleteDecorated();
delete decorated_; delete decorated;
} }
} }
...@@ -53,10 +52,10 @@ namespace AMDiS { ...@@ -53,10 +52,10 @@ namespace AMDiS {
void ElementData::serialize(std::ostream& out) void ElementData::serialize(std::ostream& out)
{ {
std::string decoratedType; std::string decoratedType;
if (decorated_) { if (decorated) {
decoratedType = decorated_->getTypeName(); decoratedType = decorated->getTypeName();
out << decoratedType << "\n"; out << decoratedType << "\n";
decorated_->serialize(out); decorated->serialize(out);
} else { } else {
out << "NULL\n"; out << "NULL\n";
} }
...@@ -64,16 +63,16 @@ namespace AMDiS { ...@@ -64,16 +63,16 @@ namespace AMDiS {
void ElementData::deserialize(std::istream& in) void ElementData::deserialize(std::istream& in)
{ {
TEST_EXIT(decorated_ == NULL) TEST_EXIT(decorated == NULL)
("there are already decorated element data\n"); ("there are already decorated element data\n");
std::string decoratedType; std::string decoratedType;
in >> decoratedType; in >> decoratedType;
in.get(); in.get();
if (decoratedType != "NULL") { if (decoratedType != "NULL") {
decorated_ = CreatorMap<ElementData>::getCreator(decoratedType)->create(); decorated = CreatorMap<ElementData>::getCreator(decoratedType)->create();
decorated_->deserialize(in); decorated->deserialize(in);
} else { } else {
decorated_ = NULL; decorated = NULL;
} }
} }
......
...@@ -43,8 +43,8 @@ namespace AMDiS { ...@@ -43,8 +43,8 @@ namespace AMDiS {
{ {
public: public:
/// constructor /// constructor
ElementData(ElementData *decorated = NULL) ElementData(ElementData *dec = NULL)
: decorated_(decorated) : decorated(dec)
{} {}
/// destructor /// destructor
...@@ -56,14 +56,14 @@ namespace AMDiS { ...@@ -56,14 +56,14 @@ namespace AMDiS {
Element* child2, Element* child2,
int elType) int elType)
{ {
if (decorated_) { if (decorated) {
bool remove = bool remove =
decorated_->refineElementData(parent, child1, child2, elType); decorated->refineElementData(parent, child1, child2, elType);
if (remove) { if (remove) {
ElementData *tmp = decorated_->decorated_; ElementData *tmp = decorated->decorated;
delete decorated_; delete decorated;
decorated_ = tmp; decorated = tmp;
} }
} }
return false; return false;
...@@ -78,8 +78,8 @@ namespace AMDiS { ...@@ -78,8 +78,8 @@ namespace AMDiS {
/// Returns a copy of this ElementData object including all decorated data. /// Returns a copy of this ElementData object including all decorated data.
virtual ElementData *clone() const virtual ElementData *clone() const
{ {
if (decorated_) if (decorated)
return decorated_->clone(); return decorated->clone();
return NULL; return NULL;
} }
...@@ -108,32 +108,32 @@ namespace AMDiS { ...@@ -108,32 +108,32 @@ namespace AMDiS {
if (this->isOfType(typeID)) { if (this->isOfType(typeID)) {
return this; return this;
} else { } else {
if (decorated_) if (decorated)
return decorated_->getElementData(typeID); return decorated->getElementData(typeID);
} }
return NULL; return NULL;
} }
inline ElementData *getDecorated(int typeID) inline ElementData *getDecorated(int typeID)
{ {
if (decorated_) if (decorated)
return decorated_->getElementData(typeID); return decorated->getElementData(typeID);
return NULL; return NULL;
} }
/** \ref /** \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. * this entry.
*/ */
bool deleteDecorated(int typeID); bool deleteDecorated(int typeID);
/// Delets the whole \ref decorated_ chain. /// Delets the whole \ref decorated chain.
void deleteDecorated(); void deleteDecorated();
inline ElementData *getDecorated() inline ElementData *getDecorated()
{ {
return decorated_; return decorated;
} }
inline void setDecorated(ElementData *d) inline void setDecorated(ElementData *d)
...@@ -142,12 +142,12 @@ namespace AMDiS { ...@@ -142,12 +142,12 @@ namespace AMDiS {
if (d != NULL) if (d != NULL)
std::cout << "leafdata decorated with nonzero" << std::endl; std::cout << "leafdata decorated with nonzero" << std::endl;
decorated_ = d; decorated = d;
} }
protected: protected:
/// Pointer to next ElementData object in the chain of responsibility. /// Pointer to next ElementData object in the chain of responsibility.
ElementData *decorated_; ElementData *decorated;
}; };
} }
......
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
// == == // == ==
// ============================================================================ // ============================================================================
/** \file ElementRegion_ED.h */ /** \file ElementRegionED.h */
#ifndef AMDIS_ELEMENTREGION_ED_H #ifndef AMDIS_ELEMENTREGIONED_H
#define AMDIS_ELEMENTREGION_ED_H #define AMDIS_ELEMENTREGIONED_H
#include "ElementData.h" #include "ElementData.h"
#include "FixVec.h" #include "FixVec.h"
...@@ -48,7 +48,7 @@ namespace AMDiS { ...@@ -48,7 +48,7 @@ namespace AMDiS {
ElementRegion_ED(ElementData *decorated = NULL) ElementRegion_ED(ElementData *decorated = NULL)
: ElementData(decorated), : ElementData(decorated),
region_(-1) region(-1)
{} {}
bool refineElementData(Element* parent, bool refineElementData(Element* parent,
...@@ -61,11 +61,11 @@ namespace AMDiS { ...@@ -61,11 +61,11 @@ namespace AMDiS {
ElementRegion_ED *ep; ElementRegion_ED *ep;
ep = new ElementRegion_ED(child1->getElementData()); ep = new ElementRegion_ED(child1->getElementData());
ep->region_ = region_; ep->region = region;
child1->setElementData(ep); child1->setElementData(ep);
ep = new ElementRegion_ED(child2->getElementData()); ep = new ElementRegion_ED(child2->getElementData());
ep->region_ = region_; ep->region = region;
child2->setElementData(ep); child2->setElementData(ep);
return false; return false;
...@@ -74,14 +74,14 @@ namespace AMDiS { ...@@ -74,14 +74,14 @@ namespace AMDiS {
ElementData *clone() const ElementData *clone() const
{ {
ElementRegion_ED *newObj = new ElementRegion_ED; ElementRegion_ED *newObj = new ElementRegion_ED;
newObj->region_ = region_; newObj->region = region;
newObj->decorated_ = ElementData::clone(); newObj->decorated = ElementData::clone();
return newObj; return newObj;
} }
inline std::string getTypeName() const inline std::string getTypeName() const
{ {
return "ElementRegion_ED"; return "ElementRegionED";
} }
inline const int getTypeID() const inline const int getTypeID() const
...@@ -92,27 +92,27 @@ namespace AMDiS { ...@@ -92,27 +92,27 @@ namespace AMDiS {
void serialize(std::ostream& out) void serialize(std::ostream& out)
{ {
ElementData::serialize(out); ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&region_), sizeof(int)); out.write(reinterpret_cast<const char*>(&region), sizeof(int));
} }
void deserialize(std::istream& in) void deserialize(std::istream& in)
{ {
ElementData::deserialize(in); ElementData::deserialize(in);
in.read(reinterpret_cast<char*>(&region_), sizeof(int)); in.read(reinterpret_cast<char*>(&region), sizeof(int));
} }
inline void setRegion(int region) inline void setRegion(int r)
{ {
region_ = region; region = r;
} }
inline int getRegion() const inline int getRegion() const
{ {
return region_; return region;
} }
protected: protected:
int region_; int region;
}; };
} }
......
...@@ -102,7 +102,7 @@ namespace AMDiS { ...@@ -102,7 +102,7 @@ namespace AMDiS {
newObj->errorEstimate = errorEstimate; newObj->errorEstimate = errorEstimate;
// clone decorated element data (=> deep copy) // clone decorated element data (=> deep copy)
newObj->decorated_ = ElementData::clone(); newObj->decorated = ElementData::clone();
// return the clone // return the clone
return newObj; return newObj;
...@@ -193,7 +193,7 @@ namespace AMDiS { ...@@ -193,7 +193,7 @@ namespace AMDiS {
newObj->errorEstimate = errorEstimate; newObj->errorEstimate = errorEstimate;
// clone decorated element data (=> deep copy) // clone decorated element data (=> deep copy)
newObj->decorated_ = ElementData::clone(); newObj->decorated = ElementData::clone();
// return the clone // return the clone
return newObj; return newObj;
...@@ -298,7 +298,7 @@ namespace AMDiS { ...@@ -298,7 +298,7 @@ namespace AMDiS {
LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL); LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL);
// clone decorated element data (=> deep copy) // clone decorated element data (=> deep copy)
newObj->decorated_ = ElementData::clone(); newObj->decorated = ElementData::clone();
// return the clone // return the clone
return newObj; return newObj;
...@@ -377,7 +377,7 @@ namespace AMDiS { ...@@ -377,7 +377,7 @@ namespace AMDiS {
newObj->coarseningError = coarseningError; newObj->coarseningError = coarseningError;
// clone decorated leaf data (=> deep copy) // clone decorated leaf data (=> deep copy)
newObj->decorated_ = ElementData::clone(); newObj->decorated = ElementData::clone();
// return the clone // return the clone
return newObj; return newObj;
...@@ -547,7 +547,7 @@ namespace AMDiS { ...@@ -547,7 +547,7 @@ namespace AMDiS {
inline ElementData *clone() const inline ElementData *clone() const
{ {
LeafDataPeriodic *newObj = new LeafDataPeriodic; LeafDataPeriodic *newObj = new LeafDataPeriodic;
newObj->decorated_ = ElementData::clone(); newObj->decorated = ElementData::clone();
return newObj; return newObj;
} }
......
...@@ -14,6 +14,12 @@ namespace AMDiS { ...@@ -14,6 +14,12 @@ namespace AMDiS {
probScal(problem) probScal(problem)
{ {
info = problem->getInfo(); 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) void ParallelDomainScal::initParallelization(AdaptInfo *adaptInfo)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define AMDIS_PARALLELDOMAINSCAL_H #define AMDIS_PARALLELDOMAINSCAL_H
#include "ParallelDomainBase.h" #include "ParallelDomainBase.h"
#include "ProblemScal.h"
namespace AMDiS { namespace AMDiS {
...@@ -34,6 +35,20 @@ namespace AMDiS { ...@@ -34,6 +35,20 @@ namespace AMDiS {
void initParallelization(AdaptInfo *adaptInfo); 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: protected:
/// Starts the solution of the linear system using Petsc. /// Starts the solution of the linear system using Petsc.
void solve(); void solve();
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "ProblemVec.h" #include "ProblemVec.h"
#include "ProblemInstat.h" #include "ProblemInstat.h"
#include "SystemVector.h" #include "SystemVector.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
...@@ -18,10 +19,18 @@ namespace AMDiS { ...@@ -18,10 +19,18 @@ namespace AMDiS {
info = probVec->getInfo(); info = probVec->getInfo();
nComponents = probVec->getNumComponents(); 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); const FiniteElemSpace *fe = probVec->getFESpace(0);
for (int i = 0; i < nComponents; i++) for (int i = 0; i < nComponents; i++)
TEST_EXIT(fe == probVec->getFESpace(i)) TEST_EXIT(fe == probVec->getFESpace(i))
("Parallelization does not supported different FE spaces!\n"); ("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));
} }
......
...@@ -42,6 +42,20 @@ namespace AMDiS { ...@@ -42,6 +42,20 @@ namespace AMDiS {
synchVectors(*(probVec->getSolution())); 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: protected:
/// Starts the solution of the linear system using Petsc. /// Starts the solution of the linear system using Petsc.
void solve(); void solve();
......
...@@ -40,16 +40,18 @@ namespace AMDiS { ...@@ -40,16 +40,18 @@ namespace AMDiS {
class PartitionElementData : public ElementData class PartitionElementData : public ElementData
{ {
public: public:
inline bool isOfType(int typeID) const { inline bool isOfType(int typeID) const
{
if (typeID == PARTITION_ED) if (typeID == PARTITION_ED)
return true; return true;
return false; return false;
} }
class Creator : public CreatorInterface<ElementData> class Creator : public CreatorInterface<ElementData>
{ {
public: public:
ElementData* create() { ElementData* create()
{
return new PartitionElementData; return new PartitionElementData;
} }
}; };
...@@ -68,10 +70,12 @@ namespace AMDiS { ...@@ -68,10 +70,12 @@ namespace AMDiS {
Element* child2, Element* child2,
int elType) int elType)
{ {
ElementData::refineElementData(parent, child1, child2, elType); ElementData::refineElementData(parent, child1, child2, elType);
PartitionElementData *child1Data = new PartitionElementData(child1->getElementData()); PartitionElementData *child1Data =
PartitionElementData *child2Data = new PartitionElementData(child2->getElementData()); new PartitionElementData(child1->getElementData());