1 #ifndef DUNE_FEM_FLOPS_HH
2 #define DUNE_FEM_FLOPS_HH
34 typedef std::vector< float > values_t ;
40 void evaluateCounters(
float& realTime,
46 int retval = PAPI_flops(&realTime, &procTime, &flop, &mFlops);
47 if( retval < PAPI_OK )
49 std::cerr <<
"ERROR: PAPI_FP_OPS event is not available, check papi_avail!" << std::endl;
56 : values_( values_t(3,
float(0.0)) ),
61 static unsigned long threadId ()
72 PAPI_thread_init( threadId );
73 PAPI_register_thread();
76 float realtime, proctime, mflops;
78 evaluateCounters( realtime, proctime, mflops, flop );
89 values_t& values = *values_;
90 long long& flop = *flop_;
91 evaluateCounters( values[ 0 ], values[ 1 ], values[ 2 ], flop );
100 void printCounter( std::ostream& out )
const
107 for(
int i=0; i<threads; ++i )
109 allStopped += stopped_[ i ];
114 if( allStopped != threads )
115 DUNE_THROW(InvalidStateException,
"Not all thread have been stopped");
117 typedef std::vector< double > result_t ;
118 result_t values( 5, 0.0 );
120 for(
int i=0; i<3; ++i )
121 values[ i ] = values_[ 0 ][ i ];
122 values[ 3 ] = flop_[ 0 ];
125 for(
int i=1; i<threads; ++i )
127 values[ 0 ] =
std::max( values[ 0 ],
double(values_[ i ][ 0 ]) );
128 values[ 1 ] =
std::max( values[ 1 ],
double(values_[ i ][ 1 ]) );
129 values[ 2 ] += values_[ i ][ 2 ];
130 values[ 3 ] += flop_[ i ];
133 values[ 3 ] /= 1.0e9 ;
135 values[ 4 ] = values[ 3 ] / values[ 0 ];
137 result_t
max( values );
138 result_t
min( values );
139 result_t
sum( values );
144 const int size =
max.size();
146 comm.max( &
max[ 0 ], size );
147 comm.min( &
min[ 0 ], size );
148 comm.sum( &
sum[ 0 ], size );
150 if( comm.rank() == 0 )
152 out <<
"FlopCounter::typ: real proc mflops flop flop/real " << std::endl;
186 static void print( std::ostream& out )
192 template <
class vec_t>
193 void printValues( std::ostream& out,
const std::string name,
const vec_t& values )
const
196 for(
unsigned int i=0; i<values.size(); ++i )
198 out << values[ i ] <<
" ";
Definition: bindguard.hh:11
static double min(const Double &v, const double p)
Definition: double.hh:386
static double max(const Double &v, const double p)
Definition: double.hh:398
static constexpr T max(T a)
Definition: utility.hh:77
static constexpr std::decay_t< T > sum(T a)
Definition: utility.hh:33
A class wrapper for the function PAPI_flops from the package PAPI. The results are CPU time,...
Definition: flops.hh:33
static void start()
Start counters.
Definition: flops.hh:172
static void print(std::ostream &out)
print values to given ostream, all values are gathered to the master rank before printing
Definition: flops.hh:186
void printValues(std::ostream &out, const std::string name, const vec_t &values) const
Definition: flops.hh:193
static void stop()
stop counters
Definition: flops.hh:178
static const CollectiveCommunication & comm()
Definition: mpimanager.hh:147
Dune::CollectiveCommunication< MPIHelper::MPICommunicator > CollectiveCommunication
Definition: mpimanager.hh:26
static int maxThreads()
return maximal number of threads possbile in the current run
Definition: threadmanager.hh:59
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:74
static int thread()
return thread number
Definition: threadmanager.hh:65
return singleton instance of given Object type.
Definition: singleton.hh:71
static Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:101