30 #ifndef SACADO_SCALAR_FLOP_COUNTER_HPP
31 #define SACADO_SCALAR_FLOP_COUNTER_HPP
43 namespace FlopCounterPack {
49 #ifdef HAVE_SACADO_CXX11
78 #ifdef HAVE_SACADO_CXX11
186 #define SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN( OP, OP_NAME ) \
187 ScalarFlopCounter<T> operator OP ( const ScalarFlopCounter<T>& s ) \
189 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
210 template <
typename U>
233 const char* names[n] = {
"Current" };
234 const char* abbr[n] = {
"count" };
248 template <
typename S>
292 template<
class T> FlopCounts ScalarFlopCounter<T>::flopCounts_;
297 #define SCALAR_FLOP_COUNTER_BINARY_OP( OP, OP_NAME ) \
299 ScalarFlopCounter<T> operator OP ( \
300 const Base< ScalarFlopCounter<T> >& aa, \
301 const Base< ScalarFlopCounter<T> >& bb ) \
303 const ScalarFlopCounter<T>& a = aa.derived(); \
304 const ScalarFlopCounter<T>& b = bb.derived(); \
305 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
306 return ScalarFlopCounter<T>(a.val() OP b.val()); \
309 ScalarFlopCounter<T> operator OP ( \
310 const typename ScalarFlopCounter<T>::value_type& a, \
311 const Base< ScalarFlopCounter<T> >& bb ) \
313 const ScalarFlopCounter<T>& b = bb.derived(); \
314 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
315 return ScalarFlopCounter<T>(a OP b.val()); \
318 ScalarFlopCounter<T> operator OP ( \
320 const Base< ScalarFlopCounter<T> >& bb ) \
322 const ScalarFlopCounter<T>& b = bb.derived(); \
323 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
324 return ScalarFlopCounter<T>(a OP b.val()); \
327 ScalarFlopCounter<T> operator OP ( \
328 const Base< ScalarFlopCounter<T> >& aa, \
329 const typename ScalarFlopCounter<T>::value_type& b ) \
331 const ScalarFlopCounter<T>& a = aa.derived(); \
332 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
333 return ScalarFlopCounter<T>(a.val() OP b); \
336 ScalarFlopCounter<T> operator OP ( \
337 const Base< ScalarFlopCounter<T> >& aa, \
340 const ScalarFlopCounter<T>& a = aa.derived(); \
341 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
342 return ScalarFlopCounter<T>(a.val() OP b); \
345 #define SCALAR_FLOP_COUNTER_UNARY_OP( OP, OP_NAME ) \
347 ScalarFlopCounter<T> operator OP ( \
348 const Base< ScalarFlopCounter<T> >& aa ) \
350 const ScalarFlopCounter<T>& a = aa.derived(); \
351 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
352 return ScalarFlopCounter<T>( OP a.val() ); \
355 #define SCALAR_FLOP_COUNTER_UNARY_FUNC( OP, OP_NAME ) \
357 ScalarFlopCounter<T> OP( \
358 const Base< ScalarFlopCounter<T> >& aa ) \
360 const ScalarFlopCounter<T>& a = aa.derived(); \
361 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
362 return ScalarFlopCounter<T>( std::OP( a.val() ) ); \
365 #define SCALAR_FLOP_COUNTER_BINARY_FUNC( OP, OP_NAME ) \
367 ScalarFlopCounter<T> OP ( \
368 const Base< ScalarFlopCounter<T> >& aa, \
369 const Base< ScalarFlopCounter<T> >& bb ) \
371 const ScalarFlopCounter<T>& a = aa.derived(); \
372 const ScalarFlopCounter<T>& b = bb.derived(); \
373 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
374 return ScalarFlopCounter<T>( std::OP( a.val(), b.val() ) ); \
377 ScalarFlopCounter<T> OP ( \
378 const typename ScalarFlopCounter<T>::value_type& a, \
379 const Base< ScalarFlopCounter<T> >& bb ) \
381 const ScalarFlopCounter<T>& b = bb.derived(); \
382 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
383 return ScalarFlopCounter<T>( std::OP( a, b.val() ) ); \
386 ScalarFlopCounter<T> OP ( \
388 const Base< ScalarFlopCounter<T> >& bb ) \
390 const ScalarFlopCounter<T>& b = bb.derived(); \
391 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
392 return ScalarFlopCounter<T>( std::OP( a, b.val() ) ); \
395 ScalarFlopCounter<T> OP ( \
396 const Base< ScalarFlopCounter<T> >& aa, \
397 const typename ScalarFlopCounter<T>::value_type& b ) \
399 const ScalarFlopCounter<T>& a = aa.derived(); \
400 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
401 return ScalarFlopCounter<T>( std::OP( a.val(), b ) ); \
404 ScalarFlopCounter<T> OP ( \
405 const Base< ScalarFlopCounter<T> >& aa, \
408 const ScalarFlopCounter<T>& a = aa.derived(); \
409 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
410 return ScalarFlopCounter<T>( std::OP(a.val(), b ) ); \
413 #define SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP( OP, OP_NAME ) \
416 const Base< ScalarFlopCounter<T> >& aa, \
417 const Base< ScalarFlopCounter<T> >& bb ) \
419 const ScalarFlopCounter<T>& a = aa.derived(); \
420 const ScalarFlopCounter<T>& b = bb.derived(); \
421 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
422 return (a.val() OP b.val()); \
426 const typename ScalarFlopCounter<T>::value_type& a, \
427 const Base< ScalarFlopCounter<T> >& bb ) \
429 const ScalarFlopCounter<T>& b = bb.derived(); \
430 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
431 return (a OP b.val()); \
435 const Base< ScalarFlopCounter<T> >& aa, \
436 const typename ScalarFlopCounter<T>::value_type& b ) \
438 const ScalarFlopCounter<T>& a = aa.derived(); \
439 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
440 return (a.val() OP b); \
449 SCALAR_FLOP_COUNTER_BINARY_OP(*,FlopCounts::MULTIPLY)
450 SCALAR_FLOP_COUNTER_BINARY_OP(/,FlopCounts::DIVIDE)
454 SCALAR_FLOP_COUNTER_UNARY_OP(-,FlopCounts::UNARY_MINUS)
461 #ifdef HAVE_SACADO_CXX11
484 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(>=,FlopCounts::GREATER_THAN_EQUAL)
485 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<,FlopCounts::LESS_THAN)
486 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<=,FlopCounts::LESS_THAN_EQUAL)
487 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(==,FlopCounts::EQUAL)
492 #endif // SACADO_SCALAR_FLOP_COUNTER_HPP
double totalFlopCount
Total flop count.
static FlopCounts flopCounts_
void reset()
Reset flop counters before starting a block of computations. */.
static FlopCounts getCounters()
Get the flop counts after a block of computations.
static void resetCounters()
Reset static flop counters before starting a block of computations.
ScalarFlopCounter< U > type
ESummaryFlopType getSummaryType(EFlopType ft)
Get summary op enum from op enum.
EFlopType
Enum for operations.
#define SACADO_ENABLE_VALUE_CTOR_DECL
void increment(EFlopType ft)
Increment an individual flop counter.
static void incrCounter(const FlopCounts::EFlopType &ft)
Increment an individual flop counter.
unsigned int partialFlopCounts[NUM_OPS]
Partial sum of individual flop counts.
const T & val() const
Return the current value.
std::ostream & printCountersTable(const int n, const char *names[], const char *abbr[], const FlopCounts counts[], std::ostream &out)
Print a list of flop counts into a single table.
static unsigned int flopGranularity
The number of flops to accumulate as an integer before converting to a double.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
Base class for Sacado types to control overload resolution.
KOKKOS_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
unsigned int partialSummaryFlopCounts[NUM_SUMMARY_OPS]
Partial sum of summary category flop counts.
Turn ScalarFlopCounter into a meta-function class usable with mpl::apply.
ScalarFlopCounter(const S &v, SACADO_ENABLE_VALUE_CTOR_DECL)
Construct to scalar value.
ESummaryFlopType
Enum of summary operation categories.
static std::ostream & printCounters(std::ostream &out)
Print the current static flop counts to out.
SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN(=, FlopCounts::ASSIGN)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
RemoveConst< T >::type value_type
Typename of values.
double summaryFlopCounts[NUM_SUMMARY_OPS]
Summary category flop counts.
FlopCounts()
Default constructor.
static const char * flopCountsNames[NUM_OPS]
Names of individual flops.
Class storing flop counts and summary flop counts.
#define SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(OP, OP_NAME)
atan2(expr1.val(), expr2.val())
Templated flop counter class.
double flopCounts[NUM_OPS]
Individual flop counts.
static const char * summaryFlopCountsNames[NUM_SUMMARY_OPS]
Names for summary operation categories.
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
#define SCALAR_FLOP_COUNTER_UNARY_FUNC(OP, OP_NAME)
#define SCALAR_FLOP_COUNTER_BINARY_OP(OP, OP_NAME)
static void finalizeCounters()
Finalize total flop count after block of computations.
ScalarFlopCounter()
Construct to uninitialized.
void val(const T &a)
Set the current value.
#define SCALAR_FLOP_COUNTER_UNARY_OP(OP, OP_NAME)
#define SCALAR_FLOP_COUNTER_BINARY_FUNC(OP, OP_NAME)