10 #ifndef SACADO_SCALAR_FLOP_COUNTER_HPP
11 #define SACADO_SCALAR_FLOP_COUNTER_HPP
23 namespace FlopCounterPack {
160 #define SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN( OP, OP_NAME ) \
161 ScalarFlopCounter<T> operator OP ( const ScalarFlopCounter<T>& s ) \
163 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
184 template <
typename U>
207 const char* names[n] = {
"Current" };
208 const char* abbr[n] = {
"count" };
222 template <
typename S>
266 template<
class T> FlopCounts ScalarFlopCounter<T>::flopCounts_;
271 #define SCALAR_FLOP_COUNTER_BINARY_OP( OP, OP_NAME ) \
273 ScalarFlopCounter<T> operator OP ( \
274 const Base< ScalarFlopCounter<T> >& aa, \
275 const Base< ScalarFlopCounter<T> >& bb ) \
277 const ScalarFlopCounter<T>& a = aa.derived(); \
278 const ScalarFlopCounter<T>& b = bb.derived(); \
279 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
280 return ScalarFlopCounter<T>(a.val() OP b.val()); \
283 ScalarFlopCounter<T> operator OP ( \
284 const typename ScalarFlopCounter<T>::value_type& a, \
285 const Base< ScalarFlopCounter<T> >& bb ) \
287 const ScalarFlopCounter<T>& b = bb.derived(); \
288 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
289 return ScalarFlopCounter<T>(a OP b.val()); \
292 ScalarFlopCounter<T> operator OP ( \
294 const Base< ScalarFlopCounter<T> >& bb ) \
296 const ScalarFlopCounter<T>& b = bb.derived(); \
297 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
298 return ScalarFlopCounter<T>(a OP b.val()); \
301 ScalarFlopCounter<T> operator OP ( \
302 const Base< ScalarFlopCounter<T> >& aa, \
303 const typename ScalarFlopCounter<T>::value_type& b ) \
305 const ScalarFlopCounter<T>& a = aa.derived(); \
306 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
307 return ScalarFlopCounter<T>(a.val() OP b); \
310 ScalarFlopCounter<T> operator OP ( \
311 const Base< ScalarFlopCounter<T> >& aa, \
314 const ScalarFlopCounter<T>& a = aa.derived(); \
315 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
316 return ScalarFlopCounter<T>(a.val() OP b); \
319 #define SCALAR_FLOP_COUNTER_UNARY_OP( OP, OP_NAME ) \
321 ScalarFlopCounter<T> operator OP ( \
322 const Base< ScalarFlopCounter<T> >& aa ) \
324 const ScalarFlopCounter<T>& a = aa.derived(); \
325 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
326 return ScalarFlopCounter<T>( OP a.val() ); \
329 #define SCALAR_FLOP_COUNTER_UNARY_FUNC( OP, OP_NAME ) \
331 ScalarFlopCounter<T> OP( \
332 const Base< ScalarFlopCounter<T> >& aa ) \
334 const ScalarFlopCounter<T>& a = aa.derived(); \
335 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
336 return ScalarFlopCounter<T>( std::OP( a.val() ) ); \
339 #define SCALAR_FLOP_COUNTER_BINARY_FUNC( OP, OP_NAME ) \
341 ScalarFlopCounter<T> OP ( \
342 const Base< ScalarFlopCounter<T> >& aa, \
343 const Base< ScalarFlopCounter<T> >& bb ) \
345 const ScalarFlopCounter<T>& a = aa.derived(); \
346 const ScalarFlopCounter<T>& b = bb.derived(); \
347 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
348 return ScalarFlopCounter<T>( std::OP( a.val(), b.val() ) ); \
351 ScalarFlopCounter<T> OP ( \
352 const typename ScalarFlopCounter<T>::value_type& a, \
353 const Base< ScalarFlopCounter<T> >& bb ) \
355 const ScalarFlopCounter<T>& b = bb.derived(); \
356 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
357 return ScalarFlopCounter<T>( std::OP( a, b.val() ) ); \
360 ScalarFlopCounter<T> OP ( \
362 const Base< ScalarFlopCounter<T> >& bb ) \
364 const ScalarFlopCounter<T>& b = bb.derived(); \
365 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
366 return ScalarFlopCounter<T>( std::OP( a, b.val() ) ); \
369 ScalarFlopCounter<T> OP ( \
370 const Base< ScalarFlopCounter<T> >& aa, \
371 const typename ScalarFlopCounter<T>::value_type& b ) \
373 const ScalarFlopCounter<T>& a = aa.derived(); \
374 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
375 return ScalarFlopCounter<T>( std::OP( a.val(), b ) ); \
378 ScalarFlopCounter<T> OP ( \
379 const Base< ScalarFlopCounter<T> >& aa, \
382 const ScalarFlopCounter<T>& a = aa.derived(); \
383 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
384 return ScalarFlopCounter<T>( std::OP(a.val(), b ) ); \
387 #define SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP( OP, OP_NAME ) \
390 const Base< ScalarFlopCounter<T> >& aa, \
391 const Base< ScalarFlopCounter<T> >& bb ) \
393 const ScalarFlopCounter<T>& a = aa.derived(); \
394 const ScalarFlopCounter<T>& b = bb.derived(); \
395 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
396 return (a.val() OP b.val()); \
400 const typename ScalarFlopCounter<T>::value_type& a, \
401 const Base< ScalarFlopCounter<T> >& bb ) \
403 const ScalarFlopCounter<T>& b = bb.derived(); \
404 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
405 return (a OP b.val()); \
409 const Base< ScalarFlopCounter<T> >& aa, \
410 const typename ScalarFlopCounter<T>::value_type& b ) \
412 const ScalarFlopCounter<T>& a = aa.derived(); \
413 ScalarFlopCounter<T>::incrCounter(OP_NAME); \
414 return (a.val() OP b); \
423 SCALAR_FLOP_COUNTER_BINARY_OP(*,FlopCounts::MULTIPLY)
424 SCALAR_FLOP_COUNTER_BINARY_OP(/,FlopCounts::DIVIDE)
428 SCALAR_FLOP_COUNTER_UNARY_OP(-,FlopCounts::UNARY_MINUS)
456 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(>=,FlopCounts::GREATER_THAN_EQUAL)
457 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<,FlopCounts::LESS_THAN)
458 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<=,FlopCounts::LESS_THAN_EQUAL)
459 SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(==,FlopCounts::EQUAL)
464 #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)