Updated examples' comments.

This commit is contained in:
Benjamin Bouvier 2012-07-24 17:12:18 +02:00
commit 09af612749
4 changed files with 21 additions and 40 deletions

View file

@ -3,6 +3,14 @@
#include <serial/eoSerial.h>
/**
* @file t-mpi-common.h
*
* This file shows an example of serialization of a primitive type, so as to be used in a parallel algorithm.
* It is fully compatible with the basic type, by implementing conversion operator and constructor based on type.
* It can contain any simple type which can be written in a std::ostream.
*/
template< class T >
struct SerializableBase : public eoserial::Persistent
{

View file

@ -34,8 +34,6 @@ Authors:
#include <mpi/eoMpi.h>
// #include <boost/mpi.hpp>
#include <vector>
using namespace std;
@ -68,6 +66,7 @@ class eoRealSerializable : public eoReal< eoMinimizingFitness >, public eoserial
void unpack( const eoserial::Object* obj )
{
this->clear();
eoserial::unpackArray< vector<double>, eoserial::Array::UnpackAlgorithm >
( *obj, "array", *this );
@ -81,40 +80,6 @@ class eoRealSerializable : public eoReal< eoMinimizingFitness >, public eoserial
fitness( fitnessVal );
}
}
/*
// Gives access to boost serialization
friend class boost::serialization::access;
template <class Archive>
void save( Archive & ar, const unsigned int version ) const
{
std::stringstream ss;
printOn( ss );
std::string asStr = ss.str();
ar & asStr;
(void) version; // avoid compilation warning
}
template <class Archive>
void load( Archive & ar, const unsigned int version )
{
std::string asStr;
ar & asStr;
std::stringstream ss;
ss << asStr;
readFrom( ss );
(void) version; // avoid compilation warning
}
// Indicates that boost save and load operations are not the same.
BOOST_SERIALIZATION_SPLIT_MEMBER()
*/
};
typedef eoRealSerializable EOT;

View file

@ -43,8 +43,6 @@ Authors:
# include "t-mpi-common.h"
// # include <boost/serialization/vector.hpp>
# include <iostream>
# include <vector>
@ -52,6 +50,13 @@ using namespace std;
using namespace eo::mpi;
/*
* This class allows the user to easily serialize a vector of elements which implement eoserial::Persistent too.
*
* T is the type of the contained element, which must implement eoserial::Persistent too.
*
* Here, it contains SerializableBase<int>, which is a serializable integer that can be used as an integer.
*/
template< class T >
struct SerializableVector : public std::vector<T>, public eoserial::Persistent
{
@ -125,7 +130,7 @@ int main(int argc, char** argv)
// eo::log << eo::setlevel( eo::debug );
Node::init( argc, argv );
if( Node::comm().size() != 7 ) {
// throw std::runtime_error("World size should be 7.");
throw std::runtime_error("World size should be 7.");
}
SerializableVector< SerializableBase<int> > v;

View file

@ -25,6 +25,9 @@ Authors:
* incremented... in a parallel fashion. While this operation is very easy to perform even on a single host, it's just
* an example for parallel apply use.
*
* The table of integers has to be serialized before it's sent. The wrapper object SerializableBase allows to serialize
* any type and manipulate it like this type: SerializableBase<int> can be exactly be used as an integer.
*
* Besides, this is also a test for assignment (scheduling) algorithms, in different cases. The test succeeds if and
* only if the program terminates without any segfault ; otherwise, there could be a deadlock which prevents the end or
* a segfault at any time.
@ -56,7 +59,7 @@ struct plusOne : public eoUF< SerializableBase<int>&, void >
{
void operator() ( SerializableBase<int> & x )
{
++x;
++x; // implicit conversion of SerializableBase<int> in the integer it contains
}
};