Serialized eoTimer with eoserial module.

This commit is contained in:
Benjamin Bouvier 2012-07-24 18:03:50 +02:00
commit 66d56bd1d8

View file

@ -30,12 +30,7 @@ Authors:
# include "utils/eoParallel.h" // eo::parallel # include "utils/eoParallel.h" // eo::parallel
# ifdef WITH_MPI # include "serial/eoSerial.h" // eo::Persistent
// For serialization purposes
# include <boost/serialization/access.hpp>
# include <boost/serialization/vector.hpp>
# include <boost/serialization/map.hpp>
# endif
/** /**
* @brief Timer allowing to measure time between a start point and a stop point. * @brief Timer allowing to measure time between a start point and a stop point.
@ -202,6 +197,9 @@ class eoTimer
* @ingroup Utilities * @ingroup Utilities
*/ */
class eoTimerStat class eoTimerStat
# ifdef WITH_MPI
: public eoserial::Persistent
# endif
{ {
public: public:
@ -215,40 +213,62 @@ class eoTimerStat
* It can readily be serialized with boost when compiling with mpi. * It can readily be serialized with boost when compiling with mpi.
*/ */
struct Stat struct Stat
# ifdef WITH_MPI
: public eoserial::Persistent
# endif
{ {
std::vector<long int> utime; std::vector<long int> utime;
std::vector<long int> stime; std::vector<long int> stime;
std::vector<double> wtime; std::vector<double> wtime;
#ifdef WITH_MPI #ifdef WITH_MPI
// Gives access to boost serialization void unpack( const eoserial::Object* obj )
friend class boost::serialization::access;
/**
* Serializes the single statistic in a boost archive (useful for boost::mpi).
* Just serializes the 3 vectors.
*/
template <class Archive>
void serialize( Archive & ar, const unsigned int version )
{ {
ar & utime & stime & wtime; utime.clear();
(void) version; // avoid compilation warning static_cast< eoserial::Array* >(obj->find("utime")->second)
->deserialize< std::vector<long int>, eoserial::Array::UnpackAlgorithm >( utime );
stime.clear();
static_cast< eoserial::Array* >(obj->find("stime")->second)
->deserialize< std::vector<long int>, eoserial::Array::UnpackAlgorithm >( stime );
wtime.clear();
static_cast< eoserial::Array* >(obj->find("wtime")->second)
->deserialize< std::vector<double>, eoserial::Array::UnpackAlgorithm >( wtime );
}
eoserial::Object* pack( void ) const
{
eoserial::Object* obj = new eoserial::Object;
obj->add("utime", eoserial::makeArray< std::vector<long int>, eoserial::MakeAlgorithm >( utime ) );
obj->add("stime", eoserial::makeArray< std::vector<long int>, eoserial::MakeAlgorithm >( stime ) );
obj->add("wtime", eoserial::makeArray< std::vector<double>, eoserial::MakeAlgorithm >( wtime ) );
return obj;
} }
# endif # endif
}; };
#ifdef WITH_MPI #ifdef WITH_MPI
// Gives access to boost serialization void unpack( const eoserial::Object* obj )
friend class boost::serialization::access;
/**
* Serializes the timerStat object in a boost archive (useful for boost::mpi).
* Just serializes the map.
*/
template <class Archive>
void serialize( Archive & ar, const unsigned int version )
{ {
ar & _stats; _stats.clear();
(void) version; // avoid compilation warning for( eoserial::Object::const_iterator it = obj->begin(), final = obj->end();
it != final;
++it)
{
eoserial::unpackObject( *obj, it->first, _stats[ it->first ] );
}
}
eoserial::Object* pack( void ) const
{
eoserial::Object* obj = new eoserial::Object;
for( std::map<std::string, Stat >::const_iterator it = _stats.begin(), final = _stats.end();
it != final;
++it)
{
obj->add( it->first, it->second.pack() );
}
return obj;
} }
# endif # endif