Merge remote-tracking branch 'eodev/master' into mpi-exp

This commit is contained in:
Benj Bouv 2013-01-30 19:29:36 +01:00
commit 70397c5ac8
7 changed files with 683 additions and 39 deletions

View file

@ -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

View file

@ -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;
};
/**
@ -203,6 +205,14 @@ class eoTimerStat
{
public:
/**
* @brief Initializes a timer stat object.
*/
eoTimerStat() : _forceDoMeasure(false)
{
// empty
}
/**
* @brief Statistic related to a key (name).
*
@ -272,6 +282,14 @@ class eoTimerStat
}
# endif
/**
* @brief Forces the measures to be retrieved.
*/
void forceDoMeasure()
{
_forceDoMeasure = true;
}
/**
* @brief Starts a new measure for the given key.
*
@ -282,7 +300,7 @@ class eoTimerStat
*/
void start( const std::string & key )
{
if( eo::parallel.doMeasure() )
if( eo::parallel.doMeasure() or _forceDoMeasure )
{
_timers[ key ].restart();
}
@ -300,7 +318,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 +336,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__