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

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

parent 1a6ac357
......@@ -44,7 +44,7 @@ available_tags=" CXX F77"
# ### BEGIN LIBTOOL CONFIG
# Libtool was configured on host p2d125:
# Libtool was configured on host deimos103:
# Shell to use when invoking shell scripts.
SHELL="/bin/sh"
......@@ -6760,7 +6760,7 @@ build_old_libs=`case $build_libtool_libs in yes) $echo no;; *) $echo yes;; esac`
# End:
# ### 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="/bin/sh"
......@@ -7065,7 +7065,7 @@ include_expsyms=""
# ### 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="/bin/sh"
......
#include <AdaptInfo.h>
#include "boost/lexical_cast.hpp"
#include "AdaptInfo.h"
#include "Serializer.h"
namespace AMDiS {
void AdaptInfo::setScalContents(int newSize) {
using boost::lexical_cast;
void AdaptInfo::setScalContents(int newSize)
{
int oldSize = scalContents.getSize();
if (newSize > oldSize) {
scalContents.resize(newSize);
char number[5];
for (int i = oldSize; i < newSize; i++) {
sprintf(number, "[%d]", i);
scalContents[i] = new ScalContent(name + std::string(number));
}
for (int i = oldSize; i < newSize; i++)
scalContents[i] =
new ScalContent(name + "[" + lexical_cast<std::string>(i) + "]");
}
}
void AdaptInfo::serialize(std::ostream& out) {
void AdaptInfo::serialize(std::ostream& out)
{
out << name << "\n";
out.write(reinterpret_cast<const char*>(&maxSpaceIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&spaceIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&timestepIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&maxTimestepIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&timeIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&maxTimeIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&time), sizeof(double));
out.write(reinterpret_cast<const char*>(&startTime), sizeof(double));
out.write(reinterpret_cast<const char*>(&endTime), sizeof(double));
out.write(reinterpret_cast<const char*>(&timestep), sizeof(double));
out.write(reinterpret_cast<const char*>(&minTimestep), sizeof(double));
out.write(reinterpret_cast<const char*>(&maxTimestep), sizeof(double));
out.write(reinterpret_cast<const char*>(&timestepNumber), sizeof(int));
out.write(reinterpret_cast<const char*>(&nTimesteps), sizeof(int));
out.write(reinterpret_cast<const char*>(&solverIterations), sizeof(int));
out.write(reinterpret_cast<const char*>(&maxSolverIterations), sizeof(int));
out.write(reinterpret_cast<const char*>(&solverTolerance), sizeof(double));
out.write(reinterpret_cast<const char*>(&solverResidual), sizeof(double));
SerUtil::serialize(out, maxSpaceIteration);
SerUtil::serialize(out, spaceIteration);
SerUtil::serialize(out, timestepIteration);
SerUtil::serialize(out, maxTimestepIteration);
SerUtil::serialize(out, timeIteration);
SerUtil::serialize(out, maxTimeIteration);
SerUtil::serialize(out, time);
SerUtil::serialize(out, startTime);
SerUtil::serialize(out, endTime);
SerUtil::serialize(out, timestep);
SerUtil::serialize(out, minTimestep);
SerUtil::serialize(out, maxTimestep);
SerUtil::serialize(out, timestepNumber);
SerUtil::serialize(out, nTimesteps);
SerUtil::serialize(out, solverIterations);
SerUtil::serialize(out, maxSolverIterations);
SerUtil::serialize(out, solverTolerance);
SerUtil::serialize(out, solverResidual);
int size = scalContents.getSize();
out.write(reinterpret_cast<const char*>(&size), sizeof(int));
SerUtil::serialize(out, size);
for (int i = 0; i < size; i++) {
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_sum)),
sizeof(double));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_t_sum)),
sizeof(double));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_max)),
sizeof(double));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_t_max)),
sizeof(double));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->spaceTolerance)),
sizeof(double));
out.write(reinterpret_cast<const char*>(&(scalContents[i]->timeTolerance)),
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));
SerUtil::serialize(out, scalContents[i]->est_sum);
SerUtil::serialize(out, scalContents[i]->est_t_sum);
SerUtil::serialize(out, scalContents[i]->est_max);
SerUtil::serialize(out, scalContents[i]->est_t_max);
SerUtil::serialize(out, scalContents[i]->spaceTolerance);
SerUtil::serialize(out, scalContents[i]->timeTolerance);
SerUtil::serialize(out, scalContents[i]->timeErrLow);
SerUtil::serialize(out, scalContents[i]->coarsenAllowed);
SerUtil::serialize(out, scalContents[i]->refinementAllowed);
SerUtil::serialize(out, scalContents[i]->refineBisections);
SerUtil::serialize(out, scalContents[i]->coarseBisections);
}
}
void AdaptInfo::deserialize(std::istream& in) {
void AdaptInfo::deserialize(std::istream& in)
{
in >> name;
in.get(); // because of std::endl in serialization
in.get();
in.read(reinterpret_cast<char*>(&maxSpaceIteration), sizeof(int));
in.read(reinterpret_cast<char*>(&spaceIteration), sizeof(int));
in.read(reinterpret_cast<char*>(&timestepIteration), sizeof(int));
in.read(reinterpret_cast<char*>(&maxTimestepIteration), sizeof(int));
in.read(reinterpret_cast<char*>(&timeIteration), sizeof(int));
in.read(reinterpret_cast<char*>(&maxTimeIteration), sizeof(int));
in.read(reinterpret_cast<char*>(&time), sizeof(double));
in.read(reinterpret_cast<char*>(&startTime), sizeof(double));
in.read(reinterpret_cast<char*>(&endTime), sizeof(double));
in.read(reinterpret_cast<char*>(&timestep), sizeof(double));
in.read(reinterpret_cast<char*>(&minTimestep), sizeof(double));
in.read(reinterpret_cast<char*>(&maxTimestep), sizeof(double));
in.read(reinterpret_cast<char*>(&timestepNumber), sizeof(int));
in.read(reinterpret_cast<char*>(&nTimesteps), sizeof(int));
in.read(reinterpret_cast<char*>(&solverIterations), sizeof(int));
in.read(reinterpret_cast<char*>(&maxSolverIterations), sizeof(int));
in.read(reinterpret_cast<char*>(&solverTolerance), sizeof(double));
in.read(reinterpret_cast<char*>(&solverResidual), sizeof(double));
int size;
in.read(reinterpret_cast<char*>(&size), sizeof(int));
SerUtil::deserialize(in, maxSpaceIteration);
SerUtil::deserialize(in, spaceIteration);
SerUtil::deserialize(in, timestepIteration);
SerUtil::deserialize(in, maxTimestepIteration);
SerUtil::deserialize(in, timeIteration);
SerUtil::deserialize(in, maxTimeIteration);
SerUtil::deserialize(in, time);
SerUtil::deserialize(in, startTime);
SerUtil::deserialize(in, endTime);
SerUtil::deserialize(in, timestep);
SerUtil::deserialize(in, minTimestep);
SerUtil::deserialize(in, maxTimestep);
SerUtil::deserialize(in, timestepNumber);
SerUtil::deserialize(in, nTimesteps);
SerUtil::deserialize(in, solverIterations);
SerUtil::deserialize(in, maxSolverIterations);
SerUtil::deserialize(in, solverTolerance);
SerUtil::deserialize(in, solverResidual);
int size = 0;
SerUtil::deserialize(in, size);
scalContents.resize(size);
for (int i = 0; i < size; i++) {
// if (!scalContents[i]) {
char number[5];
sprintf(number, "[%d]", i);
scalContents[i] = new ScalContent(name + std::string(number));
// }
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_sum)),
sizeof(double));
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_t_sum)),
sizeof(double));
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_max)),
sizeof(double));
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_t_max)),
sizeof(double));
in.read(reinterpret_cast<char*>(&(scalContents[i]->spaceTolerance)),
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));
scalContents[i] =
new ScalContent(name + "[" + lexical_cast<std::string>(i) + "]");
SerUtil::deserialize(in, scalContents[i]->est_sum);
SerUtil::deserialize(in, scalContents[i]->est_t_sum);
SerUtil::deserialize(in, scalContents[i]->est_max);
SerUtil::deserialize(in, scalContents[i]->est_t_max);
SerUtil::deserialize(in, scalContents[i]->spaceTolerance);
SerUtil::deserialize(in, scalContents[i]->timeTolerance);
SerUtil::deserialize(in, scalContents[i]->timeErrLow);
SerUtil::deserialize(in, scalContents[i]->coarsenAllowed);
SerUtil::deserialize(in, scalContents[i]->refinementAllowed);
SerUtil::deserialize(in, scalContents[i]->refineBisections);
SerUtil::deserialize(in, scalContents[i]->coarseBisections);
}
}
......
......@@ -10,8 +10,9 @@
#include "ResidualEstimator.h"
#include "LeafData.h"
#include "SurfaceRegion_ED.h"
#include "DOFMatrix.h"
#include "ElementRegion_ED.h"
#include "PartitionElementData.h"
#include "DOFMatrix.h"
#include "UmfPackSolver.h"
namespace AMDiS {
......@@ -141,6 +142,9 @@ namespace AMDiS {
creator = new ElementRegion_ED::Creator;
addCreator("ElementRegion_ED", creator);
creator = new PartitionElementData::Creator;
addCreator("PartitionElementData", creator);
}
}
......@@ -10,6 +10,7 @@
#include "Mesh.h"
#include "DOFVector.h"
#include "DOFIterator.h"
#include "Serializer.h"
namespace AMDiS {
......@@ -331,31 +332,19 @@ namespace AMDiS {
// write dofFree
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++) {
bool free = dofFree[i];
out.write(reinterpret_cast<const char*>(&free), sizeof(bool));
bool free = dofFree[i];
SerUtil::serialize(out, free);
}
// write firstHole
out.write(reinterpret_cast<const char*>(&firstHole), sizeof(unsigned int));
SerUtil::serialize(out, firstHole);
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);
// write nr0DOF
nr0DOF.serialize(out);
}
......@@ -367,33 +356,21 @@ namespace AMDiS {
// read dofFree
int s;
in.read(reinterpret_cast<char*>(&s), sizeof(int));
SerUtil::deserialize(in, s);
dofFree.resize(s);
for (int i = 0; i < s; i++) {
bool free;
in.read(reinterpret_cast<char*>(&free), sizeof(bool));
SerUtil::deserialize(in, free);
dofFree[i] = free;
}
// read firstHole
in.read(reinterpret_cast<char*>(&firstHole), sizeof(unsigned int));
SerUtil::deserialize(in, firstHole);
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);
// read nr0DOF
nr0DOF.deserialize(in);
std::list<DOFIndexedBase*>::iterator di;
......
......@@ -14,7 +14,7 @@
#include "BoundaryCondition.h"
#include "BoundaryManager.h"
#include "Assembler.h"
#include "Serializer.h"
namespace AMDiS {
......@@ -376,9 +376,67 @@ namespace AMDiS {
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)
{
matrix= rhs.matrix;
matrix = rhs.matrix;
}
void DOFMatrix::removeRowsWithDBC(std::set<int> *rows)
......
......@@ -399,79 +399,11 @@ namespace AMDiS {
return nnzPerRow;
}
private:
template <typename T>
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);
}
}
/// Writes the matrix to an output stream.
void serialize(std::ostream &out);
private:
template <typename T>
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;
}
}
/// Reads a matrix from an input stream.
void deserialize(::std::istream &in);
///
int memsize();
......
......@@ -4,6 +4,7 @@
#include "CoarseningManager.h"
#include "FixVec.h"
#include "ElementRegion_ED.h"
#include "Serializer.h"
namespace AMDiS {
......@@ -382,7 +383,7 @@ namespace AMDiS {
int dim = mesh->getDim();
int nodes = mesh->getNumberOfNodes();
int j = 0;
out.write(reinterpret_cast<const char*>(&nodes), sizeof(int));
SerUtil::serialize(out, nodes);
for (int pos = 0; pos <= dim; pos++) {
GeoIndex position = INDEX_OF_DIM(pos, dim);
......@@ -399,21 +400,21 @@ namespace AMDiS {
if (Mesh::serializedDOFs[idx] == NULL) {
Mesh::serializedDOFs[idx] = dof[j];
out.write(reinterpret_cast<const char*>(&ndof), sizeof(int));
out.write(reinterpret_cast<const char*>(&pos), sizeof(int));
SerUtil::serialize(out, ndof);
SerUtil::serialize(out, pos);
out.write(reinterpret_cast<const char*>(dof[j]),
ndof * sizeof(DegreeOfFreedom));
} else {
int minusOne = -1;
out.write(reinterpret_cast<const char*>(&minusOne), sizeof(int));
out.write(reinterpret_cast<const char*>(&pos), sizeof(int));
SerUtil::serialize(out, minusOne);
SerUtil::serialize(out, pos);
out.write(reinterpret_cast<const char*>(&(dof[j][0])),
sizeof(DegreeOfFreedom));
}
} else {
int zero = 0;
out.write(reinterpret_cast<const char*>(&zero), sizeof(int));
out.write(reinterpret_cast<const char*>(&pos), sizeof(int));
SerUtil::serialize(out, zero);
SerUtil::serialize(out, pos);
}
j++;
}
......@@ -421,10 +422,10 @@ namespace AMDiS {
}
// write index
out.write(reinterpret_cast<const char*>(&index), sizeof(int));
SerUtil::serialize(out, index);
// write mark
out.write(reinterpret_cast<const char*>(&mark), sizeof(signed char));
SerUtil::serialize(out, mark);
// write newCoord
if (newCoord) {
......@@ -447,7 +448,7 @@ namespace AMDiS {
{
FUNCNAME("Element::deserialize()");
std::string typeName;
std::string typeName = "";
// read children
in >> typeName;
......@@ -475,14 +476,14 @@ namespace AMDiS {
// read dofs
int nodes;
in.read(reinterpret_cast<char*>(&nodes), sizeof(int));
SerUtil::deserialize(in, nodes);
dof = new DegreeOfFreedom*[nodes];
for (int i = 0; i < nodes; i++) {
int nDofs, pos;
in.read(reinterpret_cast<char*>(&nDofs), sizeof(int));
in.read(reinterpret_cast<char*>(&pos), sizeof(int));
SerUtil::deserialize(in, nDofs);
SerUtil::deserialize(in, pos);
if (nDofs) {
if (nDofs != -1) {
......@@ -502,8 +503,8 @@ namespace AMDiS {
} else {
DegreeOfFreedom index;
in.read(reinterpret_cast<char*>(&index), sizeof(DegreeOfFreedom));
SerUtil::deserialize(in, index);
std::pair<DegreeOfFreedom, int> idx = std::make_pair(index, pos);
TEST_EXIT(Mesh::serializedDOFs.find(idx) != Mesh::serializedDOFs.end())
("This should never happen!\n");
......@@ -515,10 +516,10 @@ namespace AMDiS {
}