Serialized eoTimer with eoserial module.
This commit is contained in:
parent
72e26513f6
commit
66d56bd1d8
1 changed files with 49 additions and 29 deletions
|
|
@ -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,41 +213,63 @@ 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;
|
{
|
||||||
|
utime.clear();
|
||||||
|
static_cast< eoserial::Array* >(obj->find("utime")->second)
|
||||||
|
->deserialize< std::vector<long int>, eoserial::Array::UnpackAlgorithm >( utime );
|
||||||
|
|
||||||
/**
|
stime.clear();
|
||||||
* Serializes the single statistic in a boost archive (useful for boost::mpi).
|
static_cast< eoserial::Array* >(obj->find("stime")->second)
|
||||||
* Just serializes the 3 vectors.
|
->deserialize< std::vector<long int>, eoserial::Array::UnpackAlgorithm >( stime );
|
||||||
*/
|
|
||||||
template <class Archive>
|
wtime.clear();
|
||||||
void serialize( Archive & ar, const unsigned int version )
|
static_cast< eoserial::Array* >(obj->find("wtime")->second)
|
||||||
{
|
->deserialize< std::vector<double>, eoserial::Array::UnpackAlgorithm >( wtime );
|
||||||
ar & utime & stime & wtime;
|
}
|
||||||
(void) version; // avoid compilation warning
|
|
||||||
}
|
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;
|
{
|
||||||
|
_stats.clear();
|
||||||
/**
|
for( eoserial::Object::const_iterator it = obj->begin(), final = obj->end();
|
||||||
* Serializes the timerStat object in a boost archive (useful for boost::mpi).
|
it != final;
|
||||||
* Just serializes the map.
|
++it)
|
||||||
*/
|
|
||||||
template <class Archive>
|
|
||||||
void serialize( Archive & ar, const unsigned int version )
|
|
||||||
{
|
{
|
||||||
ar & _stats;
|
eoserial::unpackObject( *obj, it->first, _stats[ it->first ] );
|
||||||
(void) version; // avoid compilation warning
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Reference in a new issue