1 #ifndef DUNE_FEM_FLOPS_HH 2 #define DUNE_FEM_FLOPS_HH 33 typedef std::vector< float > values_t ;
39 void evaluateCounters(
float& realTime,
45 int retval = PAPI_flops(&realTime, &procTime, &flop, &mFlops);
46 if( retval < PAPI_OK )
48 std::cerr <<
"ERROR: PAPI_FP_OPS event is not available, check papi_avail!" << std::endl;
55 : values_( values_t(3,
float(0.0)) ),
60 static unsigned long threadId ()
71 PAPI_thread_init( threadId );
72 PAPI_register_thread();
75 float realtime, proctime, mflops;
77 evaluateCounters( realtime, proctime, mflops, flop );
88 values_t& values = *values_;
89 long long& flop = *flop_;
90 evaluateCounters( values[ 0 ], values[ 1 ], values[ 2 ], flop );
99 void printCounter( std::ostream& out )
const 106 for(
int i=0; i<threads; ++i )
108 allStopped += stopped_[ i ];
113 if( allStopped != threads )
114 DUNE_THROW(InvalidStateException,
"Not all thread have been stopped");
116 typedef std::vector< double > result_t ;
117 result_t values( 5, 0.0 );
119 for(
int i=0; i<3; ++i )
120 values[ i ] = values_[ 0 ][ i ];
121 values[ 3 ] = flop_[ 0 ];
124 for(
int i=1; i<threads; ++i )
126 values[ 0 ] =
std::max( values[ 0 ],
double(values_[ i ][ 0 ]) );
127 values[ 1 ] =
std::max( values[ 1 ],
double(values_[ i ][ 1 ]) );
128 values[ 2 ] += values_[ i ][ 2 ];
129 values[ 3 ] += flop_[ i ];
132 values[ 3 ] /= 1.0e9 ;
134 values[ 4 ] = values[ 3 ] / values[ 0 ];
136 result_t
max( values );
137 result_t
min( values );
138 result_t
sum( values );
143 const int size = max.size();
145 comm.max( &max[ 0 ], size );
146 comm.min( &min[ 0 ], size );
147 comm.sum( &sum[ 0 ], size );
149 if( comm.rank() == 0 )
151 out <<
"FlopCounter::typ: real proc mflops flop flop/real " << std::endl;
172 instance().startCounter();
178 instance().stopCounter();
184 static void print( std::ostream& out )
186 instance().printCounter( out );
190 template <
class vec_t>
191 void printValues( std::ostream& out,
const std::string name,
const vec_t& values )
const 194 for(
unsigned int i=0; i<values.size(); ++i )
196 out << values[ i ] <<
" ";
void printValues(std::ostream &out, const std::string name, const vec_t &values) const
Definition: flops.hh:191
static void stop()
stop counters
Definition: flops.hh:176
static const CollectiveCommunication & comm()
Definition: mpimanager.hh:108
static constexpr T max(T a)
Definition: utility.hh:65
static constexpr 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:31
static double max(const Double &v, const double p)
Definition: double.hh:387
static void start()
Start counters.
Definition: flops.hh:170
static int thread()
return thread number
Definition: threadmanager.hh:208
Definition: coordinate.hh:4
static void print(std::ostream &out)
print values to given ostream, all values are gathered to the master rank before printing ...
Definition: flops.hh:184
static int maxThreads()
return maximal number of threads possbile in the current run
Definition: threadmanager.hh:202
Dune::CollectiveCommunication< MPIHelper::MPICommunicator > CollectiveCommunication
Definition: mpimanager.hh:22
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:217
static double min(const Double &v, const double p)
Definition: double.hh:375