From 09af6127498fac31cba54006d9718736b8f0a618 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 24 Jul 2012 17:12:18 +0200 Subject: [PATCH] Updated examples' comments. --- eo/test/mpi/t-mpi-common.h | 8 +++++++ eo/test/mpi/t-mpi-eval.cpp | 37 +---------------------------- eo/test/mpi/t-mpi-multipleRoles.cpp | 11 ++++++--- eo/test/mpi/t-mpi-parallelApply.cpp | 5 +++- 4 files changed, 21 insertions(+), 40 deletions(-) diff --git a/eo/test/mpi/t-mpi-common.h b/eo/test/mpi/t-mpi-common.h index 4217af28..c862a05c 100644 --- a/eo/test/mpi/t-mpi-common.h +++ b/eo/test/mpi/t-mpi-common.h @@ -3,6 +3,14 @@ #include +/** + * @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 { diff --git a/eo/test/mpi/t-mpi-eval.cpp b/eo/test/mpi/t-mpi-eval.cpp index 4187c4e6..fb97701d 100644 --- a/eo/test/mpi/t-mpi-eval.cpp +++ b/eo/test/mpi/t-mpi-eval.cpp @@ -34,8 +34,6 @@ Authors: #include -// #include - #include 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, 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 - 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 - 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; diff --git a/eo/test/mpi/t-mpi-multipleRoles.cpp b/eo/test/mpi/t-mpi-multipleRoles.cpp index db4b1bb6..07f65937 100644 --- a/eo/test/mpi/t-mpi-multipleRoles.cpp +++ b/eo/test/mpi/t-mpi-multipleRoles.cpp @@ -43,8 +43,6 @@ Authors: # include "t-mpi-common.h" -// # include - # include # include @@ -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, which is a serializable integer that can be used as an integer. + */ template< class T > struct SerializableVector : public std::vector, 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 > v; diff --git a/eo/test/mpi/t-mpi-parallelApply.cpp b/eo/test/mpi/t-mpi-parallelApply.cpp index df90f0f5..04985b3f 100644 --- a/eo/test/mpi/t-mpi-parallelApply.cpp +++ b/eo/test/mpi/t-mpi-parallelApply.cpp @@ -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 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&, void > { void operator() ( SerializableBase & x ) { - ++x; + ++x; // implicit conversion of SerializableBase in the integer it contains } };