This file is indexed.

/usr/include/trilinos/Sacado_ScalarFlopCounter.hpp is in libtrilinos-sacado-dev 12.12.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
// @HEADER
// ***********************************************************************
//
//                           Sacado Package
//                 Copyright (2006) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
// USA
// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
// (etphipp@sandia.gov).
//
// ***********************************************************************
// @HEADER

#ifndef SACADO_SCALAR_FLOP_COUNTER_HPP
#define SACADO_SCALAR_FLOP_COUNTER_HPP

#include "Sacado_ConfigDefs.h"
#include "Sacado_ScalarFlopCounterTraits.hpp"
#include "Sacado_Base.hpp"
#include "Sacado_SFINAE_Macros.hpp"
#include <cmath>
#include <algorithm>    // for std::min and std::max
#include <ostream>      // for std::ostream

namespace Sacado {

  namespace FlopCounterPack {

    /// Class storing flop counts and summary flop counts
    class  FlopCounts {
    public:

#ifdef HAVE_SACADO_CXX11
      /// Number of total operation supported up till now
      enum { NUM_OPS = 35 };
#else
      /// Number of total operation supported up till now
      enum { NUM_OPS = 34 };
#endif
      /// Enum for operations
      enum EFlopType {
        ASSIGN
        ,PLUS
        ,PLUS_ASSIGN
        ,UNARY_PLUS
        ,MINUS
        ,MINUS_ASSIGN
        ,UNARY_MINUS
        ,MULTIPLY
        ,MULTIPLY_ASSIGN
        ,DIVIDE
        ,DIVIDE_ASSIGN
        ,GREATER_THAN
        ,GREATER_THAN_EQUAL
        ,LESS_THAN
        ,LESS_THAN_EQUAL
        ,EQUAL
        ,EXP
        ,LOG
        ,LOG10
        ,SQRT
#ifdef HAVE_SACADO_CXX11
        ,CBRT
#endif
        ,COS
        ,SIN
        ,TAN
        ,ACOS
        ,ASIN
        ,ATAN
        ,ATAN2
        ,COSH
        ,SINH
        ,TANH
        ,ABS
        ,POW
        ,MAX
        ,MIN
      };

      /// Number of summary operation categories
      enum { NUM_SUMMARY_OPS = 6 };

      /// Enum of summary operation categories
      enum ESummaryFlopType {
        SUMMARY_ASSIGN
        ,SUMMARY_PLUS_MINUS
        ,SUMMARY_MULTIPLY
        ,SUMMARY_DIVIDE
        ,SUMMARY_COMPARISON
        ,SUMMARY_NONLINEAR
      };

      /// Names of individual flops
      static const char* flopCountsNames[NUM_OPS];

      /// Names for summary operation categories
      static const char* summaryFlopCountsNames[NUM_SUMMARY_OPS];

      /*!
       * \brief The number of flops to accumulate as an integer before
       * converting to a double.
       */
      /*!
       * The default value is 100 000 000 and must be less than UINT_MAX-1.
       * Increasing this value may give somewhat better precision for the
       * flop count when counting very large numbers of flops.
       */
      static unsigned int flopGranularity;

      /// Individual flop counts
      double flopCounts[NUM_OPS];

      /// Summary category flop counts
      double summaryFlopCounts[NUM_SUMMARY_OPS];

      /// Total flop count
      double totalFlopCount;

      /// Default constructor
      FlopCounts();

      /// Reset flop counters before starting a block of computations. */
      void reset();

      //// Finalize total flop count after block of computations. */
      void finalize();

      /// Increment an individual flop counter.
      void increment(EFlopType ft);

    private:

      /// Get summary op enum from op enum
      ESummaryFlopType getSummaryType(EFlopType ft);

      /// Partial sum of individual flop counts
      unsigned int partialFlopCounts[NUM_OPS];

      /// Partial sum of summary category flop counts
      unsigned int partialSummaryFlopCounts[NUM_SUMMARY_OPS];
    };

    /** \brief Print a list of flop counts into a single table.
     *
     * \param  n  [in] Number of columns of flop counts
     * \param  names
     *            [in] Array (length <tt>n</tt>) of the names of each
     *            set of flop counts that will be used in the legend.
     * \param  abbr
     *            [in] Array (length <tt>n</tt>) of abbreviated names (less
     *            than 10 chars in length) that will be used as the column
     *            headings.
     * \param  counts
     *            [in] Array (length <tt>n</tt>) of the flop counts themselves.
     * \param  out
     *            [out] Stream that formated table is ouput to.
     */
    std::ostream& printCountersTable(const int n,
                                     const char* names[],
                                     const char* abbr[],
                                     const FlopCounts counts[],
                                     std::ostream &out);

    //
    // Member macros
    //

    ///
#define SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN( OP, OP_NAME )             \
    ScalarFlopCounter<T> operator OP ( const ScalarFlopCounter<T>& s )  \
    {                                                                   \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      val_ OP s.val();                                                  \
      return *this;                                                     \
    }

    /** \brief Templated flop counter class.
     *
     * The purpose of this simple abstract data type is to count flops
     * within a computation.
     */
    template<class T>
    class ScalarFlopCounter : public Base< ScalarFlopCounter<T> > {
    public:

      //! Typename of values
      typedef typename RemoveConst<T>::type value_type;

      //! Typename of scalar's (which may be different from T)
      typedef typename ScalarType<value_type>::type scalar_type;

      //! Turn ScalarFlopCounter into a meta-function class usable with mpl::apply
      template <typename U>
      struct apply {
        typedef ScalarFlopCounter<U> type;
      };

      /** @name Static functions for general clients (apply to all object with type <tt>T</tt> */
      //@{

      /** \brief Reset static flop counters before starting a block of computations. */
      static void resetCounters() { flopCounts_.reset(); }

      /** \brief Finalize total flop count after block of computations. */
      static void finalizeCounters() { flopCounts_.finalize(); }

      /** \brief Get the flop counts after a block of computations. */
      static FlopCounts getCounters() { return flopCounts_; }

      /** \brief Print the current static flop counts to <tt>out</tt>.
       *
       * This function just calls <tt>printCountersTable()</tt>.
       */
      static std::ostream& printCounters( std::ostream &out ) {
        const int n = 1;
        const char* names[n] = { "Current" };
        const char* abbr[n]  = { "count" };
        const FlopCounts counts[n] = { flopCounts_ };
        return printCountersTable( n, &names[0], &abbr[0], &counts[0], out );
      }

      //@{

      /** @name Object functions */
      //@{

      /// Construct to uninitialized
      ScalarFlopCounter() {}

      /// Construct to scalar value
      template <typename S>
      ScalarFlopCounter(const S &v, SACADO_ENABLE_VALUE_CTOR_DECL) : val_(v) {}

      /// Return the current value
      const T& val() const { return val_; }

      /// Set the current value
      void val(const T& a) { val_ = a; }

      SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN(=,FlopCounts::ASSIGN);
      SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN(+=,FlopCounts::PLUS_ASSIGN);
      SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN(-=,FlopCounts::MINUS_ASSIGN);
      SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN(*=,FlopCounts::MULTIPLY_ASSIGN);
      SCALAR_FLOP_COUNTER_BINARY_OP_ASSIGN(/=,FlopCounts::DIVIDE_ASSIGN);

      //@}

    private:

      // Static members
      static FlopCounts flopCounts_;

      // Object members
      T val_;

    public:

      /** Static public functions for non-member functions (not for general clients) */
      //@{

      /** \brief Increment an individual flop counter.
       *
       * Note, this function is ment to be used by nonmember operator
       * functions and not by general clients.
       */
      static void incrCounter( const FlopCounts::EFlopType& ft ) {
        flopCounts_.increment(ft);
      }

      //@}
    };

    // Static data members

    template<class T> FlopCounts ScalarFlopCounter<T>::flopCounts_;

    // ////////////////////////////////////////
    // Nonmember operator function macros

#define SCALAR_FLOP_COUNTER_BINARY_OP( OP, OP_NAME )                    \
    template<class T>                                                   \
    ScalarFlopCounter<T> operator OP (                                  \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>(a.val() OP b.val());                  \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> operator OP (                                  \
      const typename ScalarFlopCounter<T>::value_type& a,               \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>(a OP b.val());                        \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> operator OP (                                  \
      const int& a,                                                     \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>(a OP b.val());                        \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> operator OP (                                  \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const typename ScalarFlopCounter<T>::value_type& b )              \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>(a.val() OP b);                        \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> operator OP (                                  \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const int& b )                                                    \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>(a.val() OP b);                        \
    }

#define SCALAR_FLOP_COUNTER_UNARY_OP( OP, OP_NAME )                     \
    template<class T>                                                   \
    ScalarFlopCounter<T> operator OP (                                  \
      const Base< ScalarFlopCounter<T> >& aa )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>( OP a.val() );                        \
    }

#define SCALAR_FLOP_COUNTER_UNARY_FUNC( OP, OP_NAME )                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> OP(                                            \
      const Base< ScalarFlopCounter<T> >& aa )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>( std::OP( a.val() ) );                \
    }

#define SCALAR_FLOP_COUNTER_BINARY_FUNC( OP, OP_NAME )                  \
    template<class T>                                                   \
    ScalarFlopCounter<T> OP (                                           \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>( std::OP( a.val(), b.val() ) );       \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> OP (                                           \
      const typename ScalarFlopCounter<T>::value_type& a,               \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>( std::OP( a, b.val() ) );             \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> OP (                                           \
      const int& a,                                                     \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>( std::OP( a, b.val() ) );             \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> OP (                                           \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const typename ScalarFlopCounter<T>::value_type& b )              \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>( std::OP( a.val(), b ) );             \
    }                                                                   \
    template<class T>                                                   \
    ScalarFlopCounter<T> OP (                                           \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const int& b )                                                    \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return ScalarFlopCounter<T>( std::OP(a.val(), b ) );              \
    }

#define SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP( OP, OP_NAME )         \
    template<class T>                                                   \
    bool operator OP (                                                  \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return (a.val() OP b.val());                                      \
    }                                                                   \
    template<class T>                                                   \
    bool operator OP (                                                  \
      const typename ScalarFlopCounter<T>::value_type& a,               \
      const Base< ScalarFlopCounter<T> >& bb )                          \
    {                                                                   \
      const ScalarFlopCounter<T>& b = bb.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return (a OP b.val());                                            \
    }                                                                   \
    template<class T>                                                   \
    bool operator OP (                                                  \
      const Base< ScalarFlopCounter<T> >& aa,                           \
      const typename ScalarFlopCounter<T>::value_type& b )              \
    {                                                                   \
      const ScalarFlopCounter<T>& a = aa.derived();                     \
      ScalarFlopCounter<T>::incrCounter(OP_NAME);                       \
      return (a.val() OP b);                                            \
    }

    // ////////////////////////////////////////////
    // Nonmember operator and other functions

    // Binary operations
    SCALAR_FLOP_COUNTER_BINARY_OP(+,FlopCounts::PLUS)
    SCALAR_FLOP_COUNTER_BINARY_OP(-,FlopCounts::MINUS)
    SCALAR_FLOP_COUNTER_BINARY_OP(*,FlopCounts::MULTIPLY)
    SCALAR_FLOP_COUNTER_BINARY_OP(/,FlopCounts::DIVIDE)

    // Unary operations
    SCALAR_FLOP_COUNTER_UNARY_OP(+,FlopCounts::UNARY_PLUS)
    SCALAR_FLOP_COUNTER_UNARY_OP(-,FlopCounts::UNARY_MINUS)

    // Unary functions
    SCALAR_FLOP_COUNTER_UNARY_FUNC(exp,FlopCounts::EXP)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(log,FlopCounts::LOG)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(log10,FlopCounts::LOG10)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(sqrt,FlopCounts::SQRT)
#ifdef HAVE_SACADO_CXX11
    SCALAR_FLOP_COUNTER_UNARY_FUNC(cbrt,FlopCounts::CBRT)
#endif
    SCALAR_FLOP_COUNTER_UNARY_FUNC(cos,FlopCounts::COS)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(sin,FlopCounts::SIN)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(tan,FlopCounts::TAN)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(acos,FlopCounts::ACOS)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(asin,FlopCounts::ASIN)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(atan,FlopCounts::ATAN)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(cosh,FlopCounts::COSH)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(sinh,FlopCounts::SINH)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(tanh,FlopCounts::TANH)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(abs,FlopCounts::ABS)
    SCALAR_FLOP_COUNTER_UNARY_FUNC(fabs,FlopCounts::ABS)

    // Binary functions
    SCALAR_FLOP_COUNTER_BINARY_FUNC(atan2,FlopCounts::ATAN2)
    SCALAR_FLOP_COUNTER_BINARY_FUNC(pow,FlopCounts::POW)
    SCALAR_FLOP_COUNTER_BINARY_FUNC(max,FlopCounts::MAX)
    SCALAR_FLOP_COUNTER_BINARY_FUNC(min,FlopCounts::MIN)

    // Comparison
    SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(>,FlopCounts::GREATER_THAN)
    SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(>=,FlopCounts::GREATER_THAN_EQUAL)
    SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<,FlopCounts::LESS_THAN)
    SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(<=,FlopCounts::LESS_THAN_EQUAL)
    SCALAR_FLOP_COUNTER_BINARY_COMPARISON_OP(==,FlopCounts::EQUAL)

  } // namespace FlopCounterPack
} // namespace Sacado

#endif // SACADO_SCALAR_FLOP_COUNTER_HPP