Commit 81e22e44 authored by berenger-bramas's avatar berenger-bramas

Draft for the serialisation and sendable interface.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@392 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 40789c3f
......@@ -32,6 +32,15 @@ public:
/** Default destructor */
virtual ~FBasicCell(){
}
void save(FBufferWriter& buffer) const{
FExtendMortonIndex::save(buffer);
FExtendCoordinate::save(buffer);
}
void restore(FBufferReader& buffer){
FExtendMortonIndex::restore(buffer);
FExtendCoordinate::restore(buffer);
}
};
......
......@@ -27,8 +27,11 @@
*/
class FBasicParticle : public FExtendPosition{
public:
/** Default destructor */
virtual ~FBasicParticle(){
void save(FBufferWriter& buffer) const{
FExtendPosition::save(buffer);
}
void restore(FBufferReader& buffer){
FExtendPosition::restore(buffer);
}
};
......
......@@ -25,8 +25,13 @@
*/
class FFmaParticle : public FBasicParticle, public FExtendPhysicalValue {
public:
/** Default destructor */
virtual ~FFmaParticle(){
void save(FBufferWriter& buffer) const{
FBasicParticle::save(buffer);
FExtendPhysicalValue::save(buffer);
}
void restore(FBufferReader& buffer){
FBasicParticle::restore(buffer);
FExtendPhysicalValue::restore(buffer);
}
};
......
......@@ -50,6 +50,29 @@ public:
void setDataDown(const long long int inData){
this->dataDown = inData;
}
void save(FBufferWriter& buffer) const{
FBasicCell::save(buffer);
buffer << dataDown << dataUp;
}
void restore(FBufferReader& buffer){
FBasicCell::restore(buffer);
buffer >> dataDown >> dataUp;
}
void serializeUp(FBufferWriter& buffer) const {
buffer << this->dataUp;
}
void deserializeUp(FBufferReader& buffer){
buffer >> this->dataUp;
}
void serializeDown(FBufferWriter& buffer) const {
buffer << this->dataDown;
}
void deserializeDown(FBufferReader& buffer){
buffer >> this->dataDown;
}
};
......
......@@ -45,6 +45,15 @@ public:
void setDataDown(const long long int inData){
this->dataDown = inData;
}
void save(FBufferWriter& buffer) const{
FBasicParticle::save(buffer);
buffer << dataDown;
}
void restore(FBufferReader& buffer){
FBasicParticle::restore(buffer);
buffer >> dataDown;
}
};
......
......@@ -13,6 +13,9 @@
#include "../Utils/FGlobal.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -211,6 +214,15 @@ public:
return output; // for multiple << operators.
}
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << x << y << z;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> x >> y >> z;
}
};
......
......@@ -11,7 +11,8 @@
#ifndef FEXTENDCELLTYPE_HPP
#define FEXTENDCELLTYPE_HPP
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -67,6 +68,16 @@ public:
void setTargetsChildTrue() {
this->type |= ContainsTargets;
}
public:
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << type;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> type;
}
};
......
......@@ -14,6 +14,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Containers/FTreeCoordinate.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -58,6 +60,15 @@ public:
this->coordinate.setZ(inZ);
}
/** Save current object */
void save(FBufferWriter& buffer) const {
coordinate.save(buffer);
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
coordinate.restore(buffer);
}
};
......
......@@ -14,6 +14,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Utils/F3DPosition.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -63,6 +65,15 @@ public:
void setForces(const FReal inFx, const FReal inFy, const FReal inFz) {
this->forces.setPosition(inFx , inFy, inFz);
}
/** Save current object */
void save(FBufferWriter& buffer) const {
forces.save(buffer);
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
forces.restore(buffer);
}
};
......
// ===================================================================================
// Logiciel initial: ScalFmm Version 0.5
// Co-auteurs : Olivier Coulaud, Bérenger Bramas.
// Propriétaires : INRIA.
// Copyright © 2011-2012, diffusé sous les termes et conditions d’une licence propriétaire.
// Initial software: ScalFmm Version 0.5
// Co-authors: Olivier Coulaud, Bérenger Bramas.
// Owners: INRIA.
// Copyright © 2011-2012, spread under the terms and conditions of a proprietary license.
// ===================================================================================
#ifndef FEXTENDFULLYSENDABLE_HPP
#define FEXTENDFULLYSENDABLE_HPP
#include "../Utils/FAbstractSerializable.hpp"
#include "../Containers/FBufferWriter.hpp"
#include "../Containers/FBufferReader.hpp"
/** @author Berenger Bramas
* This extension MUST be put as the first inherited class!
* It copy the memory in the buffer read writer
*/
template <class ClassType>
class FExtendFullySerializable : public FAbstractSerializable {
public:
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << (*reinterpret_cast<const ClassType*>(this));
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> (*reinterpret_cast<ClassType*>(this));
}
};
#endif // FEXTENDFULLYSENDABLE_HPP
......@@ -14,6 +14,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Containers/FTreeCoordinate.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -51,6 +53,14 @@ public:
this->mortonIndex = inMortonIndex;
}
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << mortonIndex;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> mortonIndex;
}
};
......
......@@ -11,6 +11,8 @@
#ifndef FEXTENDPARTICLETYPE_HPP
#define FEXTENDPARTICLETYPE_HPP
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
......@@ -82,6 +84,14 @@ public:
this->type = Source;
}
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << type;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> type;
}
};
......
......@@ -13,6 +13,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -50,6 +52,15 @@ public:
this->physicalValue = inphysicalValue;
}
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << physicalValue;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> physicalValue;
}
};
......
......@@ -14,6 +14,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Utils/F3DPosition.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -70,6 +72,14 @@ public:
this->position.incZ(inPz);
}
/** Save current object */
void save(FBufferWriter& buffer) const {
position.save(buffer);
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
position.restore(buffer);
}
};
......
......@@ -13,6 +13,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -55,6 +57,14 @@ public:
this->potential += inPotential;
}
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << potential;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> potential;
}
};
......
......@@ -15,6 +15,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Utils/F3DPosition.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -64,6 +66,15 @@ public:
void setVelocity(const FReal inVx, const FReal inVy, const FReal inVz) {
this->velocity.setPosition(inVx , inVy, inVz);
}
/** Save current object */
void save(FBufferWriter& buffer) const {
buffer << velocity;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
buffer >> velocity;
}
};
......
......@@ -14,6 +14,10 @@
#include <iostream>
#include <fstream>
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/** This class proposes static methods to save and load
* a tree.
* It used binary format (so FReal must be the same!)
......@@ -27,87 +31,11 @@
*/
class FTreeIO{
public:
class FAbstractSerial {
protected:
template <class TypeClass>
void save(std::ofstream*const stream, const TypeClass& value) const{
stream->write((const char*)&value, sizeof(TypeClass));
}
template <class TypeClass>
TypeClass restore(std::ifstream*const stream) const{
TypeClass value;
stream->read((char*)&value, sizeof(TypeClass));
return value;
}
template <class TypeClass>
void saveArray(std::ofstream*const stream, const TypeClass*const values, const int size) const{
stream->write((const char*)values, sizeof(TypeClass) * size);
}
template <class TypeClass>
void restoreArray(std::ifstream*const stream, TypeClass*const values, const int size) const{
stream->read((char*)values, sizeof(TypeClass) * size);
}
public:
virtual void read(std::ifstream*const stream) = 0;
virtual void write(std::ofstream*const stream) const = 0;
};
/** The serializer class call a method on the particles or cells
* So they have to implement the write/read method
*/
template <class CellClass, class ParticleClass>
class Serializer {
public:
static void PutCell(std::ofstream*const stream, const CellClass*const cell) {
cell->write(stream);
}
static void PutParticles(std::ofstream*const stream, const ParticleClass* const particles, const int nbParticles) {
for( int idxParticle = 0 ; idxParticle < nbParticles ; ++idxParticle){
particles[idxParticle].write(stream);
}
}
static void GetCell(std::ifstream*const stream, CellClass* const cell){
cell->read(stream);
}
static void GetParticles(std::ifstream*const stream, ParticleClass* const particles, const int nbParticles){
for( int idxParticle = 0 ; idxParticle < nbParticles ; ++idxParticle){
particles[idxParticle].read(stream);
}
}
};
/** The copier method simple copy in memory using memcpy
*/
template <class CellClass, class ParticleClass>
class Copier {
public:
static void PutCell(std::ofstream*const stream, const CellClass* const cell) {
stream->write((const char*)cell, sizeof(CellClass));
}
static void PutParticles(std::ofstream*const stream, const ParticleClass* const particles, const int nbParticles) {
stream->write((const char*)particles, nbParticles * sizeof(ParticleClass));
}
static void GetCell(std::ifstream*const stream, CellClass* const cell){
stream->read((char*)cell, sizeof(CellClass));
}
static void GetParticles(std::ifstream*const stream, ParticleClass* const particles, const int nbParticles){
stream->read((char*)particles, nbParticles * sizeof(ParticleClass));
}
};
/** To save in memory */
template <class OctreeClass, class CellClass, class ParticleClass, class ClassProptotype >
static bool Save(const char filename[], OctreeClass& tree){
std::ofstream file(filename, std::ofstream::binary | std::ofstream::out );
FBufferWriter buffer;
if(!file.good()){
return false;
......@@ -130,11 +58,9 @@ public:
{
typename OctreeClass::Iterator octreeIterator(&tree);
int maxParticlesInLeaf = 0;
int nbLeaf = 0;
const std::ofstream::pos_type posNbLeaf = file.tellp();
file.write((const char*)&nbLeaf,sizeof(int));
file.write((const char*)&maxParticlesInLeaf,sizeof(int));
octreeIterator.gotoBottomLeft();
const bool useTargetSource = (octreeIterator.getCurrentListSrc() != octreeIterator.getCurrentListTargets());
......@@ -142,27 +68,50 @@ public:
do{
const int nbParticlesInLeaf = (octreeIterator.getCurrentListSrc()->getSize() + octreeIterator.getCurrentListTargets()->getSize());
file.write((const char*)&nbParticlesInLeaf,sizeof(int));
ClassProptotype::PutParticles( &file, octreeIterator.getCurrentListSrc()->data(), octreeIterator.getCurrentListSrc()->getSize());
ClassProptotype::PutParticles( &file, octreeIterator.getCurrentListTargets()->data(), octreeIterator.getCurrentListTargets()->getSize());
buffer.reset();
typename ContainerClass::BasicIterator iterSrc(*octreeIterator.getCurrentListSrc());
while( iterSrc.hasNotFinished() ){
iterSrc.data().save(buffer);
iterSrc.gotoNext();
}
typename ContainerClass::BasicIterator iterTarget(*octreeIterator.getCurrentListTargets());
while( iterTarget.hasNotFinished() ){
iterTarget.data().save(buffer);
iterTarget.gotoNext();
}
const int sizeOfLeaf = buffer.getSize();
file.write((const char*) &sizeOfLeaf, sizeof(int));
file.write(buffer.data(), buffer.getSize());
++nbLeaf;
if( maxParticlesInLeaf < nbParticlesInLeaf) maxParticlesInLeaf = nbParticlesInLeaf;
} while(octreeIterator.moveRight());
}
else{
do{
const int nbParticlesInLeaf = octreeIterator.getCurrentListSrc()->getSize();
file.write((const char*)&nbParticlesInLeaf,sizeof(int));
ClassProptotype::PutParticles( &file, octreeIterator.getCurrentListSrc()->data(), octreeIterator.getCurrentListSrc()->getSize());
buffer.reset();
typename ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListSrc());
while( iter.hasNotFinished() ){
iter.data().save(buffer);
iter.gotoNext();
}
const int sizeOfLeaf= buffer.getSize();
file.write((const char*) &sizeOfLeaf, sizeof(int));
file.write(buffer.data(), buffer.getSize());
++nbLeaf;
if( maxParticlesInLeaf < nbParticlesInLeaf) maxParticlesInLeaf = nbParticlesInLeaf;
} while(octreeIterator.moveRight());
}
const std::ofstream::pos_type currentPos = file.tellp();
file.seekp(posNbLeaf);
file.write((const char*)&nbLeaf,sizeof(int));
file.write((const char*)&maxParticlesInLeaf,sizeof(int));
file.seekp(currentPos);
}
......@@ -180,8 +129,14 @@ public:
do{
const MortonIndex mindex = octreeIterator.getCurrentGlobalIndex();
file.write((const char*)&mindex,sizeof(MortonIndex));;
ClassProptotype::PutCell( &file, octreeIterator.getCurrentCell());
file.write((const char*)&mindex,sizeof(MortonIndex));
buffer.reset();
octreeIterator.getCurrentCell()->save(buffer);
const int sizeOfCell = buffer.getSize();
file.write((const char*) &sizeOfCell, sizeof(int));
file.write(buffer.data(), buffer.getSize());
++nbCells;
} while(octreeIterator.moveRight());
......@@ -206,6 +161,7 @@ public:
template <class OctreeClass, class CellClass, class ParticleClass, class ClassProptotype >
static bool Load(const char filename[], OctreeClass& tree){
std::ifstream file(filename, std::ifstream::binary | std::ifstream::in );
FBufferReader buffer;
if(!file.good()){
return false;
......@@ -234,21 +190,24 @@ public:
{
int nbLeaf = 0;
file.read((char*)&nbLeaf, sizeof(int));
int maxParticlesInLeaf = 0;
file.read((char*)&maxParticlesInLeaf, sizeof(int));
ParticleClass* const particles = new ParticleClass[maxParticlesInLeaf];
ParticleClass particle;
for(int idxLeaf = 0 ; idxLeaf < nbLeaf ; ++idxLeaf){
int particlesInLeaf = 0;
file.read((char*)&particlesInLeaf, sizeof(int));
ClassProptotype::GetParticles(&file, particles, particlesInLeaf);
int sizeOfLeaf = 0;
file.read((char*)&sizeOfLeaf, sizeof(int));
buffer.reserve(sizeOfLeaf);
file.read((char*)buffer.data(), sizeOfLeaf);
for(int idxParticle = 0 ; idxParticle < particlesInLeaf ; ++idxParticle){
tree.insert(particles[idxParticle]);
particle.restore(buffer);
tree.insert(particle);
}
}
delete[] particles;
}
// Start from leal level - 1
......@@ -270,7 +229,14 @@ public:
return false;
}
ClassProptotype::GetCell(&file,octreeIterator.getCurrentCell());
int sizeOfCell = 0;
file.read((char*)&sizeOfCell, sizeof(int));
buffer.reserve(sizeOfCell);
file.read((char*)buffer.data(), sizeOfCell);
octreeIterator.getCurrentCell()->restore(buffer);
--nbCells;
} while(octreeIterator.moveRight());
......
......@@ -183,13 +183,12 @@ public:
// Get a computable vector
preExpNExp(temporaryMultiSource);
FReal alpha_and_beta[2] = {1.0, 0.0};
//FReal alpha_and_beta[2] = {1.0, 0.0};
cblas_gemv<FReal>(CblasColMajor, CblasTrans,
FF_MATRIX_COLUMN_DIM, FF_MATRIX_ROW_DIM,
alpha_and_beta, M2L_Outer_transfer,
FF_MATRIX_COLUMN_DIM, temporaryMultiSource, 1,
alpha_and_beta, local_exp, 1);
//CblasTrans
FBlas::gemtv( FF_MATRIX_COLUMN_DIM,FF_MATRIX_ROW_DIM,
FReal(1.0), M2L_Outer_transfer,
temporaryMultiSource, local_exp);
}
};
......