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 ()
62 return MPIManager :: thread();
68 if( ! MPIManager :: singleThreadMode() )
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
102 assert( MPIManager :: singleThreadMode () );
105 const int threads = MPIManager :: maxThreads ();
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 );
140 typedef MPIManager :: CollectiveCommunication CollectiveCommunication;
141 const CollectiveCommunication& comm = MPIManager :: comm();
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;
173 instance().startCounter();
179 instance().stopCounter();
187 instance().printCounter(
out );
191 template <
class vec_t>
192 void printValues( std::ostream&
out,
const std::string name,
const vec_t& values )
const
195 for(
unsigned int i=0; i<values.size(); ++i )
197 out << values[ i ] <<
" ";
double max(const Dune::Fem::Double &v, const double p)
Definition: double.hh:965
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
A class wrapper for the function PAPI_flops from the package PAPI. The results are CPU time,...
Definition: flops.hh:32
static void start()
Start counters.
Definition: flops.hh:171
static void print(std::ostream &out)
print values to given ostream, all values are gathered to the master rank before printing
Definition: flops.hh:185
void printValues(std::ostream &out, const std::string name, const vec_t &values) const
Definition: flops.hh:192
static void stop()
stop counters
Definition: flops.hh:177
ThreadSafeValue realizes thread safety for a given variable by creating an instance of this variable ...
Definition: threadsafevalue.hh:18
return singleton instance of given Object type.
Definition: singleton.hh:88
static DUNE_EXPORT Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:118