Commit 13579ff8 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Serialization and deserialization of parallel domain problems should now work correctly.

parent 1a6ac357
...@@ -44,7 +44,7 @@ available_tags=" CXX F77" ...@@ -44,7 +44,7 @@ available_tags=" CXX F77"
# ### BEGIN LIBTOOL CONFIG # ### BEGIN LIBTOOL CONFIG
# Libtool was configured on host p2d125: # Libtool was configured on host deimos103:
# Shell to use when invoking shell scripts. # Shell to use when invoking shell scripts.
SHELL="/bin/sh" SHELL="/bin/sh"
...@@ -6760,7 +6760,7 @@ build_old_libs=`case $build_libtool_libs in yes) $echo no;; *) $echo yes;; esac` ...@@ -6760,7 +6760,7 @@ build_old_libs=`case $build_libtool_libs in yes) $echo no;; *) $echo yes;; esac`
# End: # End:
# ### BEGIN LIBTOOL TAG CONFIG: CXX # ### BEGIN LIBTOOL TAG CONFIG: CXX
# Libtool was configured on host p2d125: # Libtool was configured on host deimos103:
# Shell to use when invoking shell scripts. # Shell to use when invoking shell scripts.
SHELL="/bin/sh" SHELL="/bin/sh"
...@@ -7065,7 +7065,7 @@ include_expsyms="" ...@@ -7065,7 +7065,7 @@ include_expsyms=""
# ### BEGIN LIBTOOL TAG CONFIG: F77 # ### BEGIN LIBTOOL TAG CONFIG: F77
# Libtool was configured on host p2d125: # Libtool was configured on host deimos103:
# Shell to use when invoking shell scripts. # Shell to use when invoking shell scripts.
SHELL="/bin/sh" SHELL="/bin/sh"
......
#include <AdaptInfo.h> #include "boost/lexical_cast.hpp"
#include "AdaptInfo.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
void AdaptInfo::setScalContents(int newSize) { using boost::lexical_cast;
void AdaptInfo::setScalContents(int newSize)
{
int oldSize = scalContents.getSize(); int oldSize = scalContents.getSize();
if (newSize > oldSize) { if (newSize > oldSize) {
scalContents.resize(newSize); scalContents.resize(newSize);
char number[5]; for (int i = oldSize; i < newSize; i++)
for (int i = oldSize; i < newSize; i++) { scalContents[i] =
sprintf(number, "[%d]", i); new ScalContent(name + "[" + lexical_cast<std::string>(i) + "]");
scalContents[i] = new ScalContent(name + std::string(number));
}
} }
} }
void AdaptInfo::serialize(std::ostream& out) { void AdaptInfo::serialize(std::ostream& out)
{
out << name << "\n"; out << name << "\n";
out.write(reinterpret_cast<const char*>(&maxSpaceIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&spaceIteration), sizeof(int)); SerUtil::serialize(out, maxSpaceIteration);
out.write(reinterpret_cast<const char*>(&timestepIteration), sizeof(int)); SerUtil::serialize(out, spaceIteration);
out.write(reinterpret_cast<const char*>(&maxTimestepIteration), sizeof(int)); SerUtil::serialize(out, timestepIteration);
out.write(reinterpret_cast<const char*>(&timeIteration), sizeof(int)); SerUtil::serialize(out, maxTimestepIteration);
out.write(reinterpret_cast<const char*>(&maxTimeIteration), sizeof(int)); SerUtil::serialize(out, timeIteration);
out.write(reinterpret_cast<const char*>(&time), sizeof(double)); SerUtil::serialize(out, maxTimeIteration);
out.write(reinterpret_cast<const char*>(&startTime), sizeof(double)); SerUtil::serialize(out, time);
out.write(reinterpret_cast<const char*>(&endTime), sizeof(double)); SerUtil::serialize(out, startTime);
out.write(reinterpret_cast<const char*>(&timestep), sizeof(double)); SerUtil::serialize(out, endTime);
out.write(reinterpret_cast<const char*>(&minTimestep), sizeof(double)); SerUtil::serialize(out, timestep);
out.write(reinterpret_cast<const char*>(&maxTimestep), sizeof(double)); SerUtil::serialize(out, minTimestep);
out.write(reinterpret_cast<const char*>(&timestepNumber), sizeof(int)); SerUtil::serialize(out, maxTimestep);
out.write(reinterpret_cast<const char*>(&nTimesteps), sizeof(int)); SerUtil::serialize(out, timestepNumber);
out.write(reinterpret_cast<const char*>(&solverIterations), sizeof(int)); SerUtil::serialize(out, nTimesteps);
out.write(reinterpret_cast<const char*>(&maxSolverIterations), sizeof(int)); SerUtil::serialize(out, solverIterations);
out.write(reinterpret_cast<const char*>(&solverTolerance), sizeof(double)); SerUtil::serialize(out, maxSolverIterations);
out.write(reinterpret_cast<const char*>(&solverResidual), sizeof(double)); SerUtil::serialize(out, solverTolerance);
SerUtil::serialize(out, solverResidual);
int size = scalContents.getSize(); int size = scalContents.getSize();
out.write(reinterpret_cast<const char*>(&size), sizeof(int)); SerUtil::serialize(out, size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_sum)), SerUtil::serialize(out, scalContents[i]->est_sum);
sizeof(double)); SerUtil::serialize(out, scalContents[i]->est_t_sum);
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_t_sum)), SerUtil::serialize(out, scalContents[i]->est_max);
sizeof(double)); SerUtil::serialize(out, scalContents[i]->est_t_max);
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_max)), SerUtil::serialize(out, scalContents[i]->spaceTolerance);
sizeof(double)); SerUtil::serialize(out, scalContents[i]->timeTolerance);
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_t_max)), SerUtil::serialize(out, scalContents[i]->timeErrLow);
sizeof(double)); SerUtil::serialize(out, scalContents[i]->coarsenAllowed);
out.write(reinterpret_cast<const char*>(&(scalContents[i]->spaceTolerance)), SerUtil::serialize(out, scalContents[i]->refinementAllowed);
sizeof(double)); SerUtil::serialize(out, scalContents[i]->refineBisections);
out.write(reinterpret_cast<const char*>(&(scalContents[i]->timeTolerance)), SerUtil::serialize(out, scalContents[i]->coarseBisections);
sizeof(double));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->timeErrLow)),
sizeof(double));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->coarsenAllowed)),
sizeof(int));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->refinementAllowed)),
sizeof(int));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->refineBisections)),
sizeof(int));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->coarseBisections)),
sizeof(int));
} }
} }
void AdaptInfo::deserialize(std::istream& in) { void AdaptInfo::deserialize(std::istream& in)
{
in >> name; in >> name;
in.get(); // because of std::endl in serialization in.get();
in.read(reinterpret_cast<char*>(&maxSpaceIteration), sizeof(int)); SerUtil::deserialize(in, maxSpaceIteration);
in.read(reinterpret_cast<char*>(&spaceIteration), sizeof(int)); SerUtil::deserialize(in, spaceIteration);
in.read(reinterpret_cast<char*>(&timestepIteration), sizeof(int)); SerUtil::deserialize(in, timestepIteration);
in.read(reinterpret_cast<char*>(&maxTimestepIteration), sizeof(int)); SerUtil::deserialize(in, maxTimestepIteration);
in.read(reinterpret_cast<char*>(&timeIteration), sizeof(int)); SerUtil::deserialize(in, timeIteration);
in.read(reinterpret_cast<char*>(&maxTimeIteration), sizeof(int)); SerUtil::deserialize(in, maxTimeIteration);
in.read(reinterpret_cast<char*>(&time), sizeof(double)); SerUtil::deserialize(in, time);
in.read(reinterpret_cast<char*>(&startTime), sizeof(double)); SerUtil::deserialize(in, startTime);
in.read(reinterpret_cast<char*>(&endTime), sizeof(double)); SerUtil::deserialize(in, endTime);
in.read(reinterpret_cast<char*>(&timestep), sizeof(double)); SerUtil::deserialize(in, timestep);
in.read(reinterpret_cast<char*>(&minTimestep), sizeof(double)); SerUtil::deserialize(in, minTimestep);
in.read(reinterpret_cast<char*>(&maxTimestep), sizeof(double)); SerUtil::deserialize(in, maxTimestep);
in.read(reinterpret_cast<char*>(&timestepNumber), sizeof(int)); SerUtil::deserialize(in, timestepNumber);
in.read(reinterpret_cast<char*>(&nTimesteps), sizeof(int)); SerUtil::deserialize(in, nTimesteps);
in.read(reinterpret_cast<char*>(&solverIterations), sizeof(int)); SerUtil::deserialize(in, solverIterations);
in.read(reinterpret_cast<char*>(&maxSolverIterations), sizeof(int)); SerUtil::deserialize(in, maxSolverIterations);
in.read(reinterpret_cast<char*>(&solverTolerance), sizeof(double)); SerUtil::deserialize(in, solverTolerance);
in.read(reinterpret_cast<char*>(&solverResidual), sizeof(double)); SerUtil::deserialize(in, solverResidual);
int size; int size = 0;
in.read(reinterpret_cast<char*>(&size), sizeof(int)); SerUtil::deserialize(in, size);
scalContents.resize(size); scalContents.resize(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// if (!scalContents[i]) { scalContents[i] =
char number[5]; new ScalContent(name + "[" + lexical_cast<std::string>(i) + "]");
sprintf(number, "[%d]", i);
scalContents[i] = new ScalContent(name + std::string(number)); SerUtil::deserialize(in, scalContents[i]->est_sum);
// } SerUtil::deserialize(in, scalContents[i]->est_t_sum);
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_sum)), SerUtil::deserialize(in, scalContents[i]->est_max);
sizeof(double)); SerUtil::deserialize(in, scalContents[i]->est_t_max);
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_t_sum)), SerUtil::deserialize(in, scalContents[i]->spaceTolerance);
sizeof(double)); SerUtil::deserialize(in, scalContents[i]->timeTolerance);
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_max)), SerUtil::deserialize(in, scalContents[i]->timeErrLow);
sizeof(double)); SerUtil::deserialize(in, scalContents[i]->coarsenAllowed);
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_t_max)), SerUtil::deserialize(in, scalContents[i]->refinementAllowed);
sizeof(double)); SerUtil::deserialize(in, scalContents[i]->refineBisections);
in.read(reinterpret_cast<char*>(&(scalContents[i]->spaceTolerance)), SerUtil::deserialize(in, scalContents[i]->coarseBisections);
sizeof(double));
in.read(reinterpret_cast<char*>(&(scalContents[i]->timeTolerance)),
sizeof(double));
in.read(reinterpret_cast<char*>(&(scalContents[i]->timeErrLow)),
sizeof(double));
in.read(reinterpret_cast<char*>(&(scalContents[i]->coarsenAllowed)),
sizeof(int));
in.read(reinterpret_cast<char*>(&(scalContents[i]->refinementAllowed)),
sizeof(int));
in.read(reinterpret_cast<char*>(&(scalContents[i]->refineBisections)),
sizeof(int));
in.read(reinterpret_cast<char*>(&(scalContents[i]->coarseBisections)),
sizeof(int));
} }
} }
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
#include "ResidualEstimator.h" #include "ResidualEstimator.h"
#include "LeafData.h" #include "LeafData.h"
#include "SurfaceRegion_ED.h" #include "SurfaceRegion_ED.h"
#include "DOFMatrix.h"
#include "ElementRegion_ED.h" #include "ElementRegion_ED.h"
#include "PartitionElementData.h"
#include "DOFMatrix.h"
#include "UmfPackSolver.h" #include "UmfPackSolver.h"
namespace AMDiS { namespace AMDiS {
...@@ -141,6 +142,9 @@ namespace AMDiS { ...@@ -141,6 +142,9 @@ namespace AMDiS {
creator = new ElementRegion_ED::Creator; creator = new ElementRegion_ED::Creator;
addCreator("ElementRegion_ED", creator); addCreator("ElementRegion_ED", creator);
creator = new PartitionElementData::Creator;
addCreator("PartitionElementData", creator);
} }
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "Mesh.h" #include "Mesh.h"
#include "DOFVector.h" #include "DOFVector.h"
#include "DOFIterator.h" #include "DOFIterator.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
...@@ -331,31 +332,19 @@ namespace AMDiS { ...@@ -331,31 +332,19 @@ namespace AMDiS {
// write dofFree // write dofFree
int s = static_cast<int>(dofFree.size()); int s = static_cast<int>(dofFree.size());
out.write(reinterpret_cast<const char*>(&s), sizeof(int)); SerUtil::serialize(out, s);
for (int i = 0; i < s; i++) { for (int i = 0; i < s; i++) {
bool free = dofFree[i]; bool free = dofFree[i];
out.write(reinterpret_cast<const char*>(&free), sizeof(bool)); SerUtil::serialize(out, free);
} }
// write firstHole SerUtil::serialize(out, firstHole);
out.write(reinterpret_cast<const char*>(&firstHole), sizeof(unsigned int)); SerUtil::serialize(out, size);
SerUtil::serialize(out, usedCount);
SerUtil::serialize(out, holeCount);
SerUtil::serialize(out, sizeUsed);
// write size
out.write(reinterpret_cast<const char*>(&size), sizeof(int));
// write usedCount
out.write(reinterpret_cast<const char*>(&usedCount), sizeof(int));
// write holeCount
out.write(reinterpret_cast<const char*>(&holeCount), sizeof(int));
// write sizeUsed
out.write(reinterpret_cast<const char*>(&sizeUsed), sizeof(int));
// write nrDOF
nrDOF.serialize(out); nrDOF.serialize(out);
// write nr0DOF
nr0DOF.serialize(out); nr0DOF.serialize(out);
} }
...@@ -367,33 +356,21 @@ namespace AMDiS { ...@@ -367,33 +356,21 @@ namespace AMDiS {
// read dofFree // read dofFree
int s; int s;
in.read(reinterpret_cast<char*>(&s), sizeof(int)); SerUtil::deserialize(in, s);
dofFree.resize(s); dofFree.resize(s);
for (int i = 0; i < s; i++) { for (int i = 0; i < s; i++) {
bool free; bool free;
in.read(reinterpret_cast<char*>(&free), sizeof(bool)); SerUtil::deserialize(in, free);
dofFree[i] = free; dofFree[i] = free;
} }
// read firstHole SerUtil::deserialize(in, firstHole);
in.read(reinterpret_cast<char*>(&firstHole), sizeof(unsigned int)); SerUtil::deserialize(in, size);
SerUtil::deserialize(in, usedCount);
SerUtil::deserialize(in, holeCount);
SerUtil::deserialize(in, sizeUsed);
// read size
in.read(reinterpret_cast<char*>(&size), sizeof(int));
// read usedCount
in.read(reinterpret_cast<char*>(&usedCount), sizeof(int));
// read holeCount
in.read(reinterpret_cast<char*>(&holeCount), sizeof(int));
// read sizeUsed
in.read(reinterpret_cast<char*>(&sizeUsed), sizeof(int));
// read nrDOF
nrDOF.deserialize(in); nrDOF.deserialize(in);
// read nr0DOF
nr0DOF.deserialize(in); nr0DOF.deserialize(in);
std::list<DOFIndexedBase*>::iterator di; std::list<DOFIndexedBase*>::iterator di;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "BoundaryCondition.h" #include "BoundaryCondition.h"
#include "BoundaryManager.h" #include "BoundaryManager.h"
#include "Assembler.h" #include "Assembler.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
...@@ -376,9 +376,67 @@ namespace AMDiS { ...@@ -376,9 +376,67 @@ namespace AMDiS {
operatorEstFactor.push_back(estFactor); operatorEstFactor.push_back(estFactor);
} }
void DOFMatrix::serialize(std::ostream &out)
{
using namespace mtl;
typedef traits::range_generator<tag::major, base_matrix_type>::type c_type;
typedef traits::range_generator<tag::nz, c_type>::type ic_type;
typedef Collection<base_matrix_type>::size_type size_type;
typedef Collection<base_matrix_type>::value_type value_type;
traits::row<base_matrix_type>::type row(matrix);
traits::col<base_matrix_type>::type col(matrix);
traits::const_value<base_matrix_type>::type value(matrix);
size_type rows= num_rows(matrix), cols= num_cols(matrix), total= matrix.nnz();
SerUtil::serialize(out, rows);
SerUtil::serialize(out, cols);
SerUtil::serialize(out, total);
for (c_type cursor(mtl::begin<tag::major>(matrix)),
cend(mtl::end<tag::major>(matrix)); cursor != cend; ++cursor)
for (ic_type icursor(mtl::begin<tag::nz>(cursor)),
icend(mtl::end<tag::nz>(cursor)); icursor != icend; ++icursor) {
size_type my_row= row(*icursor), my_col= col(*icursor);
value_type my_value= value(*icursor);
SerUtil::serialize(out, my_row);
SerUtil::serialize(out, my_col);
SerUtil::serialize(out, my_value);
}
}
void DOFMatrix::deserialize(std::istream &in)
{
using namespace mtl;
typedef Collection<base_matrix_type>::size_type size_type;
typedef Collection<base_matrix_type>::value_type value_type;
size_type rows, cols, total;
SerUtil::deserialize(in, rows);
SerUtil::deserialize(in, cols);
SerUtil::deserialize(in, total);
// Prepare matrix insertion
clear();
// matrix.change_dim(rows, cols) // do we want this?
inserter_type ins(matrix);
for (size_type i = 0; i < total; ++i) {
size_type my_row, my_col;
value_type my_value;
SerUtil::deserialize(in, my_row);
SerUtil::deserialize(in, my_col);
SerUtil::deserialize(in, my_value);
ins(my_row, my_col) << my_value;
}
}
void DOFMatrix::copy(const DOFMatrix& rhs) void DOFMatrix::copy(const DOFMatrix& rhs)
{ {
matrix= rhs.matrix; matrix = rhs.matrix;
} }
void DOFMatrix::removeRowsWithDBC(std::set<int> *rows) void DOFMatrix::removeRowsWithDBC(std::set<int> *rows)
......
...@@ -399,79 +399,11 @@ namespace AMDiS { ...@@ -399,79 +399,11 @@ namespace AMDiS {
return nnzPerRow; return nnzPerRow;
} }
private: /// Writes the matrix to an output stream.
template <typename T> void serialize(std::ostream &out);
void s_write(::std::ostream &out, const T& value)
{
out.write(reinterpret_cast<const char*>(&value), sizeof value);
}
public:
void serialize(::std::ostream &out)
{
using namespace mtl;
typedef traits::range_generator<tag::major, base_matrix_type>::type c_type;
typedef traits::range_generator<tag::nz, c_type>::type ic_type;
typedef Collection<base_matrix_type>::size_type size_type;
typedef Collection<base_matrix_type>::value_type value_type;
traits::row<base_matrix_type>::type row(matrix);
traits::col<base_matrix_type>::type col(matrix);
traits::const_value<base_matrix_type>::type value(matrix);
size_type rows= num_rows(matrix), cols= num_cols(matrix), total= matrix.nnz();
s_write(out, rows);
s_write(out, cols);
s_write(out, total);
for (c_type cursor(mtl::begin<tag::major>(matrix)), cend(mtl::end<tag::major>(matrix));
cursor != cend; ++cursor)
for (ic_type icursor(mtl::begin<tag::nz>(cursor)), icend(mtl::end<tag::nz>(cursor));
icursor != icend; ++icursor) {
size_type my_row= row(*icursor), my_col= col(*icursor);
value_type my_value= value(*icursor);
s_write(out, my_row);
s_write(out, my_col);
s_write(out, my_value);
}
}
private: /// Reads a matrix from an input stream.
template <typename T> void deserialize(::std::istream &in);
void s_read(::std::istream &in, T& value)
{
in.read(reinterpret_cast<char*>(&value), sizeof value);
}
public:
void deserialize(::std::istream &in)
{
using namespace mtl;
typedef Collection<base_matrix_type>::size_type size_type;
typedef Collection<base_matrix_type>::value_type value_type;
size_type rows, cols, total;
s_read(in, rows);
s_read(in, cols);
s_read(in, total);
// Prepare matrix insertion
clear();
// matrix.change_dim(rows, cols) // do we want this?
inserter_type ins(matrix);
for (size_type i= 0; i < total; ++i) {
size_type my_row, my_col;
value_type my_value;
s_read(in, my_row);
s_read(in, my_col);
s_read(in, my_value);
ins(my_row, my_col) << my_value;
}
}
/// ///
int memsize(); int memsize();
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "CoarseningManager.h" #include "CoarseningManager.h"
#include "FixVec.h" #include "FixVec.h"
#include "ElementRegion_ED.h" #include "ElementRegion_ED.h"
#include "Serializer.h"
namespace AMDiS {