Merge branch 'mpi-exp'
This commit is contained in:
commit
e5f7fd7f1b
9 changed files with 707 additions and 54 deletions
|
|
@ -47,6 +47,7 @@ install(DIRECTORY do es ga gp other utils
|
|||
add_subdirectory(es)
|
||||
add_subdirectory(ga)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(serial)
|
||||
|
||||
if(ENABLE_PYEO)
|
||||
add_subdirectory(pyeo)
|
||||
|
|
|
|||
|
|
@ -118,12 +118,14 @@ Entity* Parser::parseRight(const std::string & str, size_t & pos)
|
|||
{
|
||||
Entity* value = 0;
|
||||
|
||||
ignoreChars( str, pos );
|
||||
if ( str[ pos ] == '{' )
|
||||
{
|
||||
// next one is an object
|
||||
DEBUG("We read an object.")
|
||||
Object* obj = new Object;
|
||||
pos += 1;
|
||||
ignoreChars( str, pos );
|
||||
while( pos < str.size() && str[ pos ] != '}' )
|
||||
{
|
||||
parseLeft( str, pos, obj );
|
||||
|
|
@ -145,11 +147,13 @@ Entity* Parser::parseRight(const std::string & str, size_t & pos)
|
|||
DEBUG("We read an array")
|
||||
Array* array = new Array;
|
||||
pos += 1;
|
||||
ignoreChars( str, pos );
|
||||
while( pos < str.size() && str[ pos ] != ']' )
|
||||
{
|
||||
Entity* child = parseRight( str, pos );
|
||||
if ( child )
|
||||
array->push_back( child );
|
||||
ignoreChars( str, pos );
|
||||
}
|
||||
DEBUG("We've finished to read our array.")
|
||||
pos += 1; // we're on the ], go to the next char
|
||||
|
|
|
|||
|
|
@ -245,6 +245,18 @@ public :
|
|||
double normal(double mean, double stdev)
|
||||
{ return mean + normal(stdev); }
|
||||
|
||||
/**
|
||||
* @brief Forgets the last cached value of normal(), so as to be able to perform some repeatable calls to normal().
|
||||
*
|
||||
* As normal() stores a cached value for performance purposes, sequences of pseudo random numbers can't be repeated
|
||||
* when reseeding, since the cached value can be yield before a number is generated. To avoid that, this method
|
||||
* allows one to clean the cache and force to regenerate a new pseudo random number.
|
||||
*/
|
||||
void clearCache()
|
||||
{
|
||||
cached = false;
|
||||
}
|
||||
|
||||
/** Random numbers using a negative exponential distribution
|
||||
|
||||
@param mean Mean value of distribution
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Authors:
|
|||
# ifndef __EO_TIMER_H__
|
||||
# define __EO_TIMER_H__
|
||||
|
||||
# include <sys/time.h> // time()
|
||||
# include <sys/time.h> // gettimeofday()
|
||||
# include <sys/resource.h> // rusage()
|
||||
|
||||
# include <vector> // std::vector
|
||||
|
|
@ -61,7 +61,7 @@ class eoTimer
|
|||
*/
|
||||
void restart()
|
||||
{
|
||||
wc_start = time(NULL);
|
||||
gettimeofday( &wc_start, NULL );
|
||||
getrusage( RUSAGE_SELF, &_start );
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +138,9 @@ class eoTimer
|
|||
*/
|
||||
double wallclock()
|
||||
{
|
||||
return std::difftime( std::time(NULL) , wc_start );
|
||||
struct timeval wc_end;
|
||||
gettimeofday( &wc_end, NULL );
|
||||
return ( wc_end.tv_sec - wc_start.tv_sec ) + ( wc_end.tv_usec - wc_start.tv_usec ) / 1000000.;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
@ -149,7 +151,7 @@ class eoTimer
|
|||
// Remainder (in milliseconds) for system time.
|
||||
long int usremainder;
|
||||
// Structure used to measure wallclock time.
|
||||
time_t wc_start;
|
||||
struct timeval wc_start;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -196,13 +198,18 @@ class eoTimer
|
|||
*
|
||||
* @ingroup Utilities
|
||||
*/
|
||||
class eoTimerStat
|
||||
# ifdef WITH_MPI
|
||||
: public eoserial::Persistent
|
||||
# endif
|
||||
class eoTimerStat : public eoserial::Persistent
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Initializes a timer stat object.
|
||||
*/
|
||||
eoTimerStat() : _forceDoMeasure(false)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Statistic related to a key (name).
|
||||
*
|
||||
|
|
@ -212,15 +219,12 @@ class eoTimerStat
|
|||
*
|
||||
* It can readily be serialized with boost when compiling with mpi.
|
||||
*/
|
||||
struct Stat
|
||||
# ifdef WITH_MPI
|
||||
: public eoserial::Persistent
|
||||
# endif
|
||||
struct Stat : public eoserial::Persistent
|
||||
{
|
||||
std::vector<long int> utime;
|
||||
std::vector<long int> stime;
|
||||
std::vector<double> wtime;
|
||||
#ifdef WITH_MPI
|
||||
|
||||
void unpack( const eoserial::Object* obj )
|
||||
{
|
||||
utime.clear();
|
||||
|
|
@ -244,10 +248,8 @@ class eoTimerStat
|
|||
obj->add("wtime", eoserial::makeArray< std::vector<double>, eoserial::MakeAlgorithm >( wtime ) );
|
||||
return obj;
|
||||
}
|
||||
# endif
|
||||
};
|
||||
|
||||
#ifdef WITH_MPI
|
||||
void unpack( const eoserial::Object* obj )
|
||||
{
|
||||
_stats.clear();
|
||||
|
|
@ -270,7 +272,14 @@ class eoTimerStat
|
|||
}
|
||||
return obj;
|
||||
}
|
||||
# endif
|
||||
|
||||
/**
|
||||
* @brief Forces the measures to be retrieved.
|
||||
*/
|
||||
void forceDoMeasure()
|
||||
{
|
||||
_forceDoMeasure = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts a new measure for the given key.
|
||||
|
|
@ -282,7 +291,7 @@ class eoTimerStat
|
|||
*/
|
||||
void start( const std::string & key )
|
||||
{
|
||||
if( eo::parallel.doMeasure() )
|
||||
if( eo::parallel.doMeasure() or _forceDoMeasure )
|
||||
{
|
||||
_timers[ key ].restart();
|
||||
}
|
||||
|
|
@ -300,7 +309,7 @@ class eoTimerStat
|
|||
*/
|
||||
void stop( const std::string& key )
|
||||
{
|
||||
if( eo::parallel.doMeasure() )
|
||||
if( eo::parallel.doMeasure() or _forceDoMeasure )
|
||||
{
|
||||
Stat & s = _stats[ key ];
|
||||
eoTimer & t = _timers[ key ];
|
||||
|
|
@ -318,11 +327,21 @@ class eoTimerStat
|
|||
return _stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Empties the statistics map.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
_stats.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
// Statistics map: links a key (string) to a statistic.
|
||||
std::map< std::string, Stat > _stats;
|
||||
// Timers map: links a key to its timer.
|
||||
std::map< std::string, eoTimer > _timers;
|
||||
// boolean to force the retrieval of statistics
|
||||
bool _forceDoMeasure;
|
||||
};
|
||||
|
||||
# endif // __TIMER_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue