30 #ifndef SACADO_SCALAR_FLOP_COUNTER_HPP
31 #define SACADO_SCALAR_FLOP_COUNTER_HPP
43 namespace FlopCounterPack {
180 #define SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN( OP, OP_NAME ) \
181 ScalarFlopCounter<T> operator OP ( const ScalarFlopCounter<T>& s ) \
183 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
204 template <
typename U>
227 const char* names[n] = {
"Current" };
228 const char* abbr[n] = {
"count" };
242 template <
typename S>
286 template<
class T> FlopCounts ScalarFlopCounter<T>::flopCounts_;
291 #define SCALAR_FLOP_COUNTER_BINARY_OP( OP, OP_NAME ) \
293 ScalarFlopCounter<T> operator OP ( \
294 const Base< ScalarFlopCounter<T> >& aa, \
295 const Base< ScalarFlopCounter<T> >& bb ) \
297 const ScalarFlopCounter<T>& a = aa.derived(); \
298 const ScalarFlopCounter<T>& b = bb.derived(); \
299 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
300 return ScalarFlopCounter<T>(a.val() OP b.val()); \
303 ScalarFlopCounter<T> operator OP ( \
304 const typename ScalarFlopCounter<T>::value_type& a, \
305 const Base< ScalarFlopCounter<T> >& bb ) \
307 const ScalarFlopCounter<T>& b = bb.derived(); \
308 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
309 return ScalarFlopCounter<T>(a OP b.val()); \
312 ScalarFlopCounter<T> operator OP ( \
314 const Base< ScalarFlopCounter<T> >& bb ) \
316 const ScalarFlopCounter<T>& b = bb.derived(); \
317 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
318 return ScalarFlopCounter<T>(a OP b.val()); \
321 ScalarFlopCounter<T> operator OP ( \
322 const Base< ScalarFlopCounter<T> >& aa, \
323 const typename ScalarFlopCounter<T>::value_type& b ) \
325 const ScalarFlopCounter<T>& a = aa.derived(); \
326 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
327 return ScalarFlopCounter<T>(a.val() OP b); \
330 ScalarFlopCounter<T> operator OP ( \
331 const Base< ScalarFlopCounter<T> >& aa, \
334 const ScalarFlopCounter<T>& a = aa.derived(); \
335 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
336 return ScalarFlopCounter<T>(a.val() OP b); \
339 #define SCALAR_FLOP_COUNTER_UNARY_OP( OP, OP_NAME ) \
341 ScalarFlopCounter<T> operator OP ( \
342 const Base< ScalarFlopCounter<T> >& aa ) \
344 const ScalarFlopCounter<T>& a = aa.derived(); \
345 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
346 return ScalarFlopCounter<T>( OP a.val() ); \
349 #define SCALAR_FLOP_COUNTER_UNARY_FUNC( OP, OP_NAME ) \
351 ScalarFlopCounter<T> OP( \
352 const Base< ScalarFlopCounter<T> >& aa ) \
354 const ScalarFlopCounter<T>& a = aa.derived(); \
355 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
356 return ScalarFlopCounter<T>( std::OP( a.val() ) ); \
359 #define SCALAR_FLOP_COUNTER_BINARY_FUNC( OP, OP_NAME ) \
361 ScalarFlopCounter<T> OP ( \
362 const Base< ScalarFlopCounter<T> >& aa, \
363 const Base< ScalarFlopCounter<T> >& bb ) \
365 const ScalarFlopCounter<T>& a = aa.derived(); \
366 const ScalarFlopCounter<T>& b = bb.derived(); \
367 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
368 return ScalarFlopCounter<T>( std::OP( a.val(), b.val() ) ); \
371 ScalarFlopCounter<T> OP ( \
372 const typename ScalarFlopCounter<T>::value_type& a, \
373 const Base< ScalarFlopCounter<T> >& bb ) \
375 const ScalarFlopCounter<T>& b = bb.derived(); \
376 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
377 return ScalarFlopCounter<T>( std::OP( a, b.val() ) ); \
380 ScalarFlopCounter<T> OP ( \
382 const Base< ScalarFlopCounter<T> >& bb ) \
384 const ScalarFlopCounter<T>& b = bb.derived(); \
385 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
386 return ScalarFlopCounter<T>( std::OP( a, b.val() ) ); \
389 ScalarFlopCounter<T> OP ( \
390 const Base< ScalarFlopCounter<T> >& aa, \
391 const typename ScalarFlopCounter<T>::value_type& b ) \
393 const ScalarFlopCounter<T>& a = aa.derived(); \
394 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
395 return ScalarFlopCounter<T>( std::OP( a.val(), b ) ); \
398 ScalarFlopCounter<T> OP ( \
399 const Base< ScalarFlopCounter<T> >& aa, \
402 const ScalarFlopCounter<T>& a = aa.derived(); \
403 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
404 return ScalarFlopCounter<T>( std::OP(a.val(), b ) ); \
407 #define SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP( OP, OP_NAME ) \
410 const Base< ScalarFlopCounter<T> >& aa, \
411 const Base< ScalarFlopCounter<T> >& bb ) \
413 const ScalarFlopCounter<T>& a = aa.derived(); \
414 const ScalarFlopCounter<T>& b = bb.derived(); \
415 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
416 return (a.val() OP b.val()); \
420 const typename ScalarFlopCounter<T>::value_type& a, \
421 const Base< ScalarFlopCounter<T> >& bb ) \
423 const ScalarFlopCounter<T>& b = bb.derived(); \
424 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
425 return (a OP b.val()); \
429 const Base< ScalarFlopCounter<T> >& aa, \
430 const typename ScalarFlopCounter<T>::value_type& b ) \
432 const ScalarFlopCounter<T>& a = aa.derived(); \
433 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
434 return (a.val() OP b); \
443 SCALAR_FLOP_COUNTER_BINARY_OP(*,FlopCounts::MULTIPLY)
444 SCALAR_FLOP_COUNTER_BINARY_OP(/,FlopCounts::DIVIDE)
448 SCALAR_FLOP_COUNTER_UNARY_OP(-,FlopCounts::UNARY_MINUS)
476 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(>=,FlopCounts::GREATER_THAN_EQUAL)
477 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<,FlopCounts::LESS_THAN)
478 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<=,FlopCounts::LESS_THAN_EQUAL)
479 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(==,FlopCounts::EQUAL)
484 #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.
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)
SACADO_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)
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)