HPCToolkit
Metric-AExprIncr.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // class Prof::Metric::AExpr and derived classes
50 //
51 // An abstract expression that represents derived expressions that are
52 // incrementally computed because all inputs are not available at one
53 // time.
54 //
55 // Since all sources are *not* known in advance, it is necessary to
56 // use an 'accumulator' that is incrementally updated and serves as both
57 // an input and output on each update. This implies that is is
58 // necessary, in general, to have an initialization routine so the
59 // accumulator is correctly initialized before the first update.
60 // Additionally, since some metrics rely on the total number of
61 // inputs, a finalization routine is also necessary.
62 //
63 // Currently supported expressions are
64 // MinIncr : min expression
65 // MaxIncr : max expression
66 // SumIncr : sum expression
67 // MeanIncr : mean (arithmetic) expression
68 // StdDevIncr : standard deviation expression
69 // CoefVarIncr: coefficient of variance
70 // RStdDevIncr: relative standard deviation
71 //
72 //***************************************************************************
73 
74 #ifndef prof_Prof_Metric_AExprIncr_hpp
75 #define prof_Prof_Metric_AExprIncr_hpp
76 
77 //************************ System Include Files ******************************
78 
79 #include <iostream>
80 #include <string>
81 
82 #include <cfloat>
83 #include <cmath>
84 
85 //************************* User Include Files *******************************
86 
87 #include "Metric-IData.hpp"
88 #include "Metric-IDBExpr.hpp"
89 
91 #include <lib/support/NaN.h>
92 #include <lib/support/Unique.hpp>
93 #include <lib/support/StrUtil.hpp>
94 
95 
96 //************************ Forward Declarations ******************************
97 
98 //****************************************************************************
99 
100 #define epsilon (0.000001)
101 
102 namespace Prof {
103 
104 namespace Metric {
105 
106 // ----------------------------------------------------------------------
107 // class AExprIncr
108 // The base class for all concrete evaluation classes
109 // ----------------------------------------------------------------------
110 
112  : public IDBExpr,
113  public Unique // disable copying, for now
114 {
115 public:
116  // fixme: return this with 'constexpr' after switching to std C++11
117  // static const double epsilon = 0.000001;
118 
119 public:
121  : m_numSrcFxd(0), m_numSrcVarId(Metric::IData::npos)
122  {
123  m_accumId[0] = accumId;
124  m_srcId[0] = srcId;
125  for (uint i = 1; i < maxAccums; ++i) {
128  }
129  }
130 
132  : m_numSrcFxd(0), m_numSrcVarId(Metric::IData::npos)
133  {
134  m_accumId[0] = accumId;
135  m_srcId[0] = srcId;
136  m_accumId[1] = accum2Id;
138  for (uint i = 2; i < maxAccums; ++i) {
141  }
142  }
143 
144  virtual ~AExprIncr()
145  { }
146 
147 
148  // ------------------------------------------------------------
149  // functions for computing a metric incrementally
150  // ------------------------------------------------------------
151 
153 
154  // initialize: initializes destination metrics (accumVar() & accum2Var())
155  virtual double
156  initialize(Metric::IData& mdata) const = 0;
157 
158  // initializeSrc: initializes source metrics (srcVar() & srcVar2())
159  virtual double
160  initializeSrc(Metric::IData& mdata) const = 0;
161 
162  // accumulate: updates accumulators using an individual source, srcVar().
163  virtual double
164  accumulate(Metric::IData& mdata) const = 0;
165 
166  // combine: updates accumulators with sources that themselves
167  // represent accumulators. There is one source for each accumulator
168  // (srcVar() & srcVar2()).
169  virtual double
170  combine(Metric::IData& mdata) const = 0;
171 
172  // finalize: finalizes destination metrics using numSrc()
173  virtual double
174  finalize(Metric::IData& mdata) const = 0;
175 
176 
177  // ------------------------------------------------------------
178  // Metric::IDBExpr: exported formulas for Flat and Callers view
179  // (other functions are distributed below)
180  // ------------------------------------------------------------
181 
182  virtual std::string
185 
186 
187  // ------------------------------------------------------------
188  // accum: accumulator
189  // accum2: accumulator2 (if needed)
190  // ------------------------------------------------------------
191 
192  // Metric::IDBExpr
193  virtual uint
194  accumId(int i) const
195  { return m_accumId[i]; }
196 
197  void
198  accumId(int i, uint x)
199  { m_accumId[i] = x; }
200 
201  double
202  accumVar(int i, const Metric::IData& mdata) const
203  { return var(mdata, m_accumId[i]); }
204 
205  double&
206  accumVar(int i, Metric::IData& mdata) const
207  { return var(mdata, m_accumId[i]); }
208 
209 
210  // Metric::IDBExpr
211  virtual uint
212  numAccum() const
213  { return 1; }
214 
215 
216  // ------------------------------------------------------------
217  // srcId: input source for accumulate()
218  // ------------------------------------------------------------
219 
220  void
221  srcId(int i, uint x)
222  { m_srcId[i] = x; }
223 
224  double
225  srcVar(int i, const Metric::IData& mdata) const
226  { return var(mdata, m_srcId[i]); }
227 
228  double&
229  srcVar(int i, Metric::IData& mdata) const
230  { return var(mdata, m_srcId[i]); }
231 
232  std::string
233  srcStr(int i) const
234  { return "$"+ StrUtil::toStr(m_srcId[i]); }
235 
236 
237  bool
238  isSetSrc(int i) const
239  { return (m_srcId[i] != Metric::IData::npos); }
240 
241  // ------------------------------------------------------------
242  // numSrcFix: number of inputs for CCT (fixed)
243  // numSrcVar: number of inputs, which can be variable
244  // ------------------------------------------------------------
245 
246  // Metric::IDBExpr
247  virtual bool
248  hasNumSrcVar() const
249  { return false; }
250 
251  uint
252  numSrc(const Metric::IData& mdata) const
253  { return (hasNumSrcVar()) ? numSrcVarVar(mdata) : m_numSrcFxd; }
254 
255 
256  // Metric::IDBExpr
257  virtual uint
258  numSrcFxd() const
259  { return m_numSrcFxd; }
260 
261  void
263  { m_numSrcFxd = x; }
264 
265 
266  bool
268  { return (m_numSrcVarId != Metric::IData::npos); }
269 
270  // Metric::IDBExpr
271  virtual uint
272  numSrcVarId() const
273  { return m_numSrcVarId; }
274 
275  void
277  { m_numSrcVarId = x; }
278 
279  uint
280  numSrcVarVar(const Metric::IData& mdata) const
281  { return (uint)var(mdata, m_numSrcVarId); }
282 
283 
284  // ------------------------------------------------------------
285  // R- or L-Value of variable reference (cf. AExpr::Var)
286  // ------------------------------------------------------------
287 
288  static double&
289  var(Metric::IData& mdata, uint mId)
290  { return mdata.demandMetric(mId); }
291 
292  static double
293  var(const Metric::IData& mdata, uint mId)
294  { return mdata.demandMetric(mId); }
295 
296 
297  // ------------------------------------------------------------
298  //
299  // ------------------------------------------------------------
300 
301  static bool
302  isok(double x)
303  { return !(c_isnan_d(x) || c_isinf_d(x)); }
304 
305 
306 public:
307  // ------------------------------------------------------------
308  // common functions for standard deviation
309  // ------------------------------------------------------------
310 
311  double
313  {
314  accumVar(0, mdata) = 0.0;
315  accumVar(1, mdata) = 0.0;
316  return 0.0;
317  }
318 
319 
320  double
322  {
323  srcVar(0, mdata) = 0.0;
324  if (isSetSrc(1)) {
325  srcVar(1, mdata) = 0.0;
326  }
327  return 0.0;
328  }
329 
330 
331  double
333  {
334  double a1 = accumVar(0, mdata), a2 = accumVar(1, mdata), s = srcVar(0, mdata);
335  double z1 = a1 + s; // running sum
336  double z2 = a2 + (s * s); // running sum of squares
337  accumVar(0, mdata) = z1;
338  accumVar(1, mdata) = z2;
339  return z1;
340  }
341 
342 
343  double
345  {
346  double a1 = accumVar(0, mdata), a2 = accumVar(1, mdata);
347  double s1 = srcVar(0, mdata), s2 = srcVar(1, mdata);
348  double z1 = a1 + s1; // running sum
349  double z2 = a2 + s2; // running sum of squares
350  accumVar(0, mdata) = z1;
351  accumVar(1, mdata) = z2;
352  return z1;
353  }
354 
355 
356  double
358  {
359  double a1 = accumVar(0, mdata); // running sum
360  double a2 = accumVar(1, mdata); // running sum of squares
361  double sdev = a1;
362  if (numSrc(mdata) > 0) {
363  double n = numSrc(mdata);
364  double mean = a1 / n;
365  double z1 = (mean * mean); // (mean)^2
366  double z2 = a2 / n; // (sum of squares)/n
367  sdev = sqrt(z2 - z1); // stddev
368 
369  accumVar(0, mdata) = sdev;
370  accumVar(1, mdata) = mean;
371  }
372  return sdev;
373  }
374 
375 
376  // ------------------------------------------------------------
377  //
378  // ------------------------------------------------------------
379 
380  virtual std::string
381  toString() const;
382 
383 
384  virtual std::ostream&
385  dump(std::ostream& os = std::cout) const
386  {
387  dumpMe(os);
388  return os;
389  }
390 
391  virtual std::ostream&
392  dumpMe(std::ostream& os = std::cout) const = 0;
393 
394  // Metric::IDBExpr::ddump()
395 
396 protected:
397  uint m_accumId[maxAccums]; // accumulators
398  uint m_srcId[maxAccums]; // input source for accumulate()
399  uint m_numSrcFxd; // number of inputs (fixed)
400  uint m_numSrcVarId; // number of inputs, which can be variable
401 };
402 
403 
404 // ----------------------------------------------------------------------
405 // MinIncr: (observational min instead of absolute min)
406 // ----------------------------------------------------------------------
407 
408 // Computes observational min instead of absolute min. Reports
409 // DBL_MIN when there have been no obervations.
410 
411 // In the abstract, we could could use initialize()/initializeSrc() to
412 // make DBL_MAX the one non-obervational value. However there are two
413 // artificial problems with this. First there are difficulties in
414 // hpcprof-mpi (see comments associated with 'FnInitSrc' in
415 // src/tool/hpcprof-mpi/main.cpp). Second, it requires a finalize
416 // function string that converts DBL_MAX to DBL_MIN (the preferred
417 // reported value), which is difficult to generate.
418 //
419 // Our solution is to (a) use DBL_MIN and 0.0 as the two
420 // non-observational values and (b) maintain the accumulator so that
421 // no conversion at finalization from DBL_MAX to DBL_MIN is required.
422 // This requires some additional tests within accumulate() and
423 // combine().
424 
425 
426 class MinIncr
427  : public AExprIncr
428 {
429 public:
431  : AExprIncr(accumId, srcId)
432  { }
433 
434  virtual ~MinIncr()
435  { }
436 
437 
438  // ------------------------------------------------------------
439  //
440  // ------------------------------------------------------------
441 
442  virtual double
443  initialize(Metric::IData& mdata) const
444  { return (accumVar(0, mdata) = DBL_MIN /* sic; see above */); }
445 
446  virtual double
448  { return (srcVar(0, mdata) = DBL_MIN /* sic; see above */); }
449 
450  virtual double
451  accumulate(Metric::IData& mdata) const
452  {
453  double a = accumVar(0, mdata), s = srcVar(0, mdata);
454  double z = a;
455 
456  // See comments above
457  if (s != DBL_MIN && s != 0.0) {
458  z = (a == DBL_MIN) ? s : std::min(a, s);
459  accumVar(0, mdata) = z;
460  }
461  DIAG_MsgIf(0, "MinIncr: min("<< a << ", " << s << ") = " << z);
462 
463  return z;
464  }
465 
466  virtual double
467  combine(Metric::IData& mdata) const
468  { return MinIncr::accumulate(mdata); }
469 
470  virtual double
471  finalize(Metric::IData& mdata) const
472  { return accumVar(0, mdata); }
473 
474 
475  // ------------------------------------------------------------
476  // Metric::IDBExpr: exported formulas for Flat and Callers view
477  // ------------------------------------------------------------
478 
479  virtual std::string
481  { return combineString1Min(); }
482 
483  virtual std::string
485  { return finalizeStringMin(); }
486 
487 
488  // ------------------------------------------------------------
489  //
490  // ------------------------------------------------------------
491 
492  virtual std::ostream&
493  dumpMe(std::ostream& os = std::cout) const;
494 
495 private:
496 };
497 
498 
499 // ----------------------------------------------------------------------
500 // MaxIncr
501 // ----------------------------------------------------------------------
502 
503 class MaxIncr
504  : public AExprIncr
505 {
506 public:
508  : AExprIncr(accumId, srcId)
509  { }
510 
511  virtual ~MaxIncr()
512  { }
513 
514 
515  // ------------------------------------------------------------
516  //
517  // ------------------------------------------------------------
518 
519  virtual double
520  initialize(Metric::IData& mdata) const
521  { return (accumVar(0, mdata) = 0.0); }
522 
523  virtual double
525  { return (srcVar(0, mdata) = 0.0); }
526 
527  virtual double
528  accumulate(Metric::IData& mdata) const
529  {
530  double a = accumVar(0, mdata), s = srcVar(0, mdata);
531  double z = std::max(a, s);
532  DIAG_MsgIf(0, "MaxIncr: max("<< a << ", " << s << ") = " << z);
533  accumVar(0, mdata) = z;
534  return z;
535  }
536 
537  virtual double
538  combine(Metric::IData& mdata) const
539  { return MaxIncr::accumulate(mdata); }
540 
541  virtual double
542  finalize(Metric::IData& mdata) const
543  { return accumVar(0, mdata); }
544 
545 
546  // ------------------------------------------------------------
547  // Metric::IDBExpr: exported formulas for Flat and Callers view
548  // ------------------------------------------------------------
549 
550  virtual std::string
552  { return combineString1Max(); }
553 
554  virtual std::string
556  { return finalizeStringMax(); }
557 
558 
559  // ------------------------------------------------------------
560  //
561  // ------------------------------------------------------------
562 
563  virtual std::ostream&
564  dumpMe(std::ostream& os = std::cout) const;
565 
566 private:
567 };
568 
569 
570 // ----------------------------------------------------------------------
571 // SumIncr
572 // ----------------------------------------------------------------------
573 
574 class SumIncr
575  : public AExprIncr
576 {
577 public:
579  : AExprIncr(accumId, srcId)
580  { }
581 
582  virtual ~SumIncr()
583  { }
584 
585 
586  // ------------------------------------------------------------
587  //
588  // ------------------------------------------------------------
589 
590  virtual double
591  initialize(Metric::IData& mdata) const
592  { return (accumVar(0, mdata) = 0.0); }
593 
594  virtual double
596  { return (srcVar(0, mdata) = 0.0); }
597 
598  virtual double
599  accumulate(Metric::IData& mdata) const
600  {
601  double a = accumVar(0, mdata), s = srcVar(0, mdata);
602  double z = a + s;
603  DIAG_MsgIf(0, "SumIncr: +("<< a << ", " << s << ") = " << z);
604  accumVar(0, mdata) = z;
605  return z;
606  }
607 
608  virtual double
609  combine(Metric::IData& mdata) const
610  { return SumIncr::accumulate(mdata); }
611 
612  virtual double
613  finalize(Metric::IData& mdata) const
614  { return accumVar(0, mdata); }
615 
616 
617  // ------------------------------------------------------------
618  // Metric::IDBExpr: exported formulas for Flat and Callers view
619  // ------------------------------------------------------------
620 
621  virtual std::string
623  { return combineString1Sum(); }
624 
625  virtual std::string
627  { return finalizeStringSum(); }
628 
629 
630  // ------------------------------------------------------------
631  //
632  // ------------------------------------------------------------
633 
634  virtual std::ostream&
635  dumpMe(std::ostream& os = std::cout) const;
636 
637 private:
638 };
639 
640 
641 // ----------------------------------------------------------------------
642 // MeanIncr
643 // ----------------------------------------------------------------------
644 
645 class MeanIncr
646  : public AExprIncr
647 {
648 public:
650  : AExprIncr(accumId, srcId)
651  { }
652 
653  virtual ~MeanIncr()
654  { }
655 
656 
657  // ------------------------------------------------------------
658  //
659  // ------------------------------------------------------------
660 
661  virtual double
662  initialize(Metric::IData& mdata) const
663  { return (accumVar(0, mdata) = 0.0); }
664 
665  virtual double
667  { return (srcVar(0, mdata) = 0.0); }
668 
669  virtual double
670  accumulate(Metric::IData& mdata) const
671  {
672  double a = accumVar(0, mdata), s = srcVar(0, mdata);
673  double z = a + s;
674  DIAG_MsgIf(0, "MeanIncr: +("<< a << ", " << s << ") = " << z);
675  accumVar(0, mdata) = z;
676  return z;
677  }
678 
679  virtual double
680  combine(Metric::IData& mdata) const
681  { return MeanIncr::accumulate(mdata); }
682 
683  virtual double
684  finalize(Metric::IData& mdata) const
685  {
686  double a = accumVar(0, mdata);
687  double z = a;
688  if (numSrc(mdata) > 0) {
689  double n = numSrc(mdata);
690  z = a / n;
691  accumVar(0, mdata) = z;
692  }
693  return z;
694  }
695 
696 
697  // ------------------------------------------------------------
698  // Metric::IDBExpr: exported formulas for Flat and Callers view
699  // ------------------------------------------------------------
700 
701  virtual bool
702  hasNumSrcVar() const
703  { return true; }
704 
705  virtual std::string
707  { return combineString1Mean(); }
708 
709  virtual std::string
711  { return finalizeStringMean(); }
712 
713 
714  // ------------------------------------------------------------
715  //
716  // ------------------------------------------------------------
717 
718  virtual std::ostream&
719  dumpMe(std::ostream& os = std::cout) const;
720 
721 private:
722 };
723 
724 
725 // ----------------------------------------------------------------------
726 // StdDevIncr: standard deviation
727 // ----------------------------------------------------------------------
728 
730  : public AExprIncr
731 {
732 public:
734  : AExprIncr(accumId, accum2Id, srcId)
735  { }
736 
737  virtual ~StdDevIncr()
738  { }
739 
740 
741  // ------------------------------------------------------------
742  //
743  // ------------------------------------------------------------
744 
745  virtual double
746  initialize(Metric::IData& mdata) const
747  { return initializeStdDev(mdata); }
748 
749  virtual double
751  { return initializeSrcStdDev(mdata); }
752 
753  virtual double
754  accumulate(Metric::IData& mdata) const
755  { return accumulateStdDev(mdata); }
756 
757  virtual double
758  combine(Metric::IData& mdata) const
759  { return combineStdDev(mdata); }
760 
761  virtual double
762  finalize(Metric::IData& mdata) const
763  { return finalizeStdDev(mdata); }
764 
765 
766  // ------------------------------------------------------------
767  // Metric::IDBExpr: exported formulas for Flat and Callers view
768  // ------------------------------------------------------------
769 
770  virtual uint
771  numAccum() const
772  { return 2; }
773 
774  virtual bool
775  hasNumSrcVar() const
776  { return true; }
777 
778  virtual std::string
780  { return combineString1StdDev(); }
781 
782  virtual std::string
784  { return combineString2StdDev(); }
785 
786  virtual std::string
788  { return finalizeStringStdDev(); }
789 
790 
791  // ------------------------------------------------------------
792  //
793  // ------------------------------------------------------------
794 
795  virtual std::ostream&
796  dumpMe(std::ostream& os = std::cout) const;
797 
798 private:
799 };
800 
801 
802 // ----------------------------------------------------------------------
803 // CoefVarIncr: relative standard deviation
804 // ----------------------------------------------------------------------
805 
807  : public AExprIncr
808 {
809 public:
811  : AExprIncr(accumId, accum2Id, srcId)
812  { }
813 
814  virtual ~CoefVarIncr()
815  { }
816 
817 
818  // ------------------------------------------------------------
819  //
820  // ------------------------------------------------------------
821 
822  virtual double
823  initialize(Metric::IData& mdata) const
824  { return initializeStdDev(mdata); }
825 
826  virtual double
828  { return initializeSrcStdDev(mdata); }
829 
830  virtual double
831  accumulate(Metric::IData& mdata) const
832  { return accumulateStdDev(mdata); }
833 
834  virtual double
835  combine(Metric::IData& mdata) const
836  { return combineStdDev(mdata); }
837 
838  virtual double
839  finalize(Metric::IData& mdata) const
840  {
841  double sdev = finalizeStdDev(mdata);
842  double mean = accumVar(1, mdata);
843  double z = 0.0;
844  if (mean > epsilon) {
845  z = sdev / mean;
846  }
847  accumVar(0, mdata) = z;
848  return z;
849  }
850 
851 
852  // ------------------------------------------------------------
853  // Metric::IDBExpr: exported formulas for Flat and Callers view
854  // ------------------------------------------------------------
855 
856  virtual int
857  hasAccum() const
858  { return 2; }
859 
860  virtual bool
861  hasNumSrcVar() const
862  { return true; }
863 
864  virtual std::string
866  { return combineString1StdDev(); }
867 
868  virtual std::string
870  { return combineString2StdDev(); }
871 
872  virtual std::string
874  { return finalizeStringCoefVar(); }
875 
876 
877  // ------------------------------------------------------------
878  //
879  // ------------------------------------------------------------
880 
881  virtual std::ostream&
882  dumpMe(std::ostream& os = std::cout) const;
883 
884 private:
885 };
886 
887 
888 // ----------------------------------------------------------------------
889 // RStdDevIncr: relative standard deviation
890 // ----------------------------------------------------------------------
891 
893  : public AExprIncr
894 {
895 public:
897  : AExprIncr(accumId, accum2Id, srcId)
898  { }
899 
900  virtual ~RStdDevIncr()
901  { }
902 
903 
904  // ------------------------------------------------------------
905  //
906  // ------------------------------------------------------------
907 
908  virtual double
909  initialize(Metric::IData& mdata) const
910  { return initializeStdDev(mdata); }
911 
912  virtual double
914  { return initializeSrcStdDev(mdata); }
915 
916  virtual double
917  accumulate(Metric::IData& mdata) const
918  { return accumulateStdDev(mdata); }
919 
920  virtual double
921  combine(Metric::IData& mdata) const
922  { return combineStdDev(mdata); }
923 
924  virtual double
925  finalize(Metric::IData& mdata) const
926  {
927  double sdev = finalizeStdDev(mdata);
928  double mean = accumVar(1, mdata);
929  double z = 0.0;
930  if (mean > epsilon) {
931  z = (sdev / mean) * 100;
932  }
933  accumVar(0, mdata) = z;
934  return z;
935  }
936 
937 
938  // ------------------------------------------------------------
939  // Metric::IDBExpr: exported formulas for Flat and Callers view
940  // ------------------------------------------------------------
941 
942  virtual uint
943  numAccum() const
944  { return 2; }
945 
946  virtual bool
947  hasNumSrcVar() const
948  { return true; }
949 
950  virtual std::string
952  { return combineString1StdDev(); }
953 
954  virtual std::string
956  { return combineString2StdDev(); }
957 
958  virtual std::string
960  { return finalizeStringRStdDev(); }
961 
962 
963  // ------------------------------------------------------------
964  //
965  // ------------------------------------------------------------
966 
967  virtual std::ostream&
968  dumpMe(std::ostream& os = std::cout) const;
969 
970 private:
971 };
972 
973 
974 // ----------------------------------------------------------------------
975 // NumSourceIncr: A special metric for representing the number of
976 // inputs for an AExprIncr.
977 // ----------------------------------------------------------------------
978 
980  : public AExprIncr
981 {
982 public:
984  : AExprIncr(accumId, srcId)
985  { }
986 
987  virtual ~NumSourceIncr()
988  { }
989 
990 
991  // ------------------------------------------------------------
992  //
993  // ------------------------------------------------------------
994 
995  virtual double
996  initialize(Metric::IData& mdata) const
997  {
998  double z = accumVar(0, mdata) = numSrcFxd();
999  return z;
1000  }
1001 
1002  virtual double
1004  { return 0.0; }
1005 
1006  virtual double
1008  { return accumVar(0, mdata); }
1009 
1010  virtual double
1011  combine(Metric::IData& mdata) const
1012  { return accumVar(0, mdata); }
1013 
1014  virtual double
1015  finalize(Metric::IData& mdata) const
1016  { return accumVar(0, mdata); }
1017 
1018 
1019  // ------------------------------------------------------------
1020  // Metric::IDBExpr: exported formulas for Flat and Callers view
1021  // ------------------------------------------------------------
1022 
1023  virtual std::string
1025  { return combineString1NumSource(); }
1026 
1027  virtual std::string
1029  { return finalizeStringNumSource(); }
1030 
1031 
1032  // ------------------------------------------------------------
1033  //
1034  // ------------------------------------------------------------
1035 
1036  virtual std::ostream&
1037  dumpMe(std::ostream& os = std::cout) const;
1038 
1039 private:
1040 };
1041 
1042 //****************************************************************************
1043 
1044 } // namespace Metric
1045 
1046 } // namespace Prof
1047 
1048 //****************************************************************************
1049 
1050 #endif /* prof_Prof_Metric_AExprIncr_hpp */
virtual std::string combineString1() const
virtual std::string finalizeString() const
MinIncr(uint accumId, uint srcId)
virtual std::string combineString1() const
std::string combineString2StdDev() const
virtual double initialize(Metric::IData &mdata) const
virtual double accumulate(Metric::IData &mdata) const
void srcId(int i, uint x)
bool isSetSrc(int i) const
virtual double initializeSrc(Metric::IData &mdata) const
std::string finalizeStringStdDev(std::string *meanRet=NULL) const
std::string finalizeStringSum() const
virtual double accumulate(Metric::IData &mdata) const
virtual double finalize(Metric::IData &mdata) const
std::string combineString1NumSource() const
virtual std::string combineString1() const
std::string finalizeStringCoefVar() const
double & accumVar(int i, Metric::IData &mdata) const
virtual double combine(Metric::IData &mdata) const
string toStr(const int x, int base)
Definition: StrUtil.cpp:243
virtual std::string combineString1() const
double accumVar(int i, const Metric::IData &mdata) const
virtual bool hasNumSrcVar() const
virtual double initialize(Metric::IData &mdata) const
double accumulateStdDev(Metric::IData &mdata) const
virtual double finalize(Metric::IData &mdata) const
virtual double finalize(Metric::IData &mdata) const
const char * DIAG_Unimplemented
virtual double initialize(Metric::IData &mdata) const
virtual std::string combineString2() const
bool c_isinf_d(double x)
Definition: NaN.c:85
virtual double combine(Metric::IData &mdata) const =0
virtual std::string finalizeString() const
static double var(const Metric::IData &mdata, uint mId)
virtual double initializeSrc(Metric::IData &mdata) const
virtual std::ostream & dumpMe(std::ostream &os=std::cout) const =0
double finalizeStdDev(Metric::IData &mdata) const
std::string finalizeStringNumSource() const
virtual std::string combineString1() const
virtual std::string combineString2() const
virtual double initializeSrc(Metric::IData &mdata) const
virtual double combine(Metric::IData &mdata) const
#define epsilon
virtual double initialize(Metric::IData &mdata) const
virtual std::string combineString1() const
virtual double finalize(Metric::IData &mdata) const
virtual double initializeSrc(Metric::IData &mdata) const
virtual std::string finalizeString() const
virtual std::string finalizeString() const
virtual double accumulate(Metric::IData &mdata) const
virtual bool hasNumSrcVar() const
std::string finalizeStringRStdDev() const
double initializeSrcStdDev(Metric::IData &mdata) const
virtual double initializeSrc(Metric::IData &GCC_ATTR_UNUSED mdata) const
virtual double combine(Metric::IData &mdata) const
virtual double accumulate(Metric::IData &mdata) const =0
virtual double finalize(Metric::IData &mdata) const =0
#define DIAG_MsgIf(ifexpr,...)
Definition: diagnostics.h:236
virtual double combine(Metric::IData &mdata) const
std::string srcStr(int i) const
AExprIncr(uint accumId, uint srcId)
virtual bool hasNumSrcVar() const
static bool isok(double x)
virtual double accumulate(Metric::IData &mdata) const
virtual double accumulate(Metric::IData &mdata) const
virtual std::string combineString1() const
unsigned int uint
Definition: uint.h:124
static double & var(Metric::IData &mdata, uint mId)
std::string combineString1Max() const
StdDevIncr(uint accumId, uint accum2Id, uint srcId)
std::string finalizeStringMean() const
virtual double finalize(Metric::IData &mdata) const
virtual double combine(Metric::IData &mdata) const
std::string combineString1Min() const
virtual uint numAccum() const
virtual double accumulate(Metric::IData &mdata) const
virtual uint numSrcVarId() const
virtual int hasAccum() const
virtual double initializeSrc(Metric::IData &mdata) const
double combineStdDev(Metric::IData &mdata) const
virtual double initializeSrc(Metric::IData &mdata) const =0
virtual std::string combineString2() const
virtual std::string combineString2() const
std::string combineString1Mean() const
virtual std::string finalizeString() const
virtual double combine(Metric::IData &mdata) const
virtual std::string combineString1() const
virtual bool hasNumSrcVar() const
virtual bool hasNumSrcVar() const
bool c_isnan_d(double x)
Definition: NaN.c:78
virtual double initialize(Metric::IData &mdata) const
virtual double initializeSrc(Metric::IData &mdata) const
virtual double accumulate(Metric::IData &mdata) const
virtual uint accumId(int i) const
virtual std::string finalizeString() const
double demandMetric(size_t mId, size_t size=0) const
virtual double initialize(Metric::IData &mdata) const
virtual double finalize(Metric::IData &mdata) const
uint numSrc(const Metric::IData &mdata) const
NumSourceIncr(uint accumId, uint srcId)
std::string finalizeStringMin() const
virtual double combine(Metric::IData &mdata) const
void accumId(int i, uint x)
virtual std::string toString() const
MeanIncr(uint accumId, uint srcId)
virtual std::string finalizeString() const
virtual double combine(Metric::IData &mdata) const
virtual double initialize(Metric::IData &mdata) const
virtual uint numSrcFxd() const
virtual uint numAccum() const
std::string finalizeStringMax() const
uint numSrcVarVar(const Metric::IData &mdata) const
std::string combineString1Sum() const
RStdDevIncr(uint accumId, uint accum2Id, uint srcId)
virtual double initializeSrc(Metric::IData &mdata) const
std::string combineString1StdDev() const
virtual std::string finalizeString() const
#define DIAG_Die(...)
Definition: diagnostics.h:267
virtual std::ostream & dump(std::ostream &os=std::cout) const
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80
<!-- ********************************************************************--> n<!-- HPCToolkit Experiment DTD --> n<!-- Version 2.1 --> n<!-- ********************************************************************--> n<!ELEMENT HPCToolkitExperiment(Header,(SecCallPathProfile|SecFlatProfile) *)> n<!ATTLIST HPCToolkitExperiment\n version CDATA #REQUIRED > n n<!-- ******************************************************************--> n n<!-- Info/NV:flexible name-value pairs:(n) ame;(t) ype;(v) alue --> n<!ELEMENT Info(NV *)> n<!ATTLIST Info\n n CDATA #IMPLIED > n<!ELEMENT NV EMPTY > n<!ATTLIST NV\n n CDATA #REQUIRED\n t CDATA #IMPLIED\n v CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Header --> n<!-- ******************************************************************--> n<!ELEMENT Header(Info *)> n<!ATTLIST Header\n n CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Section Header --> n<!-- ******************************************************************--> n<!ELEMENT SecHeader(MetricTable?, MetricDBTable?, TraceDBTable?, LoadModuleTable?, FileTable?, ProcedureTable?, Info *)> n n<!-- MetricTable:--> n<!ELEMENT MetricTable(Metric) * > n n<!-- Metric:(i) d;(n) ame --> n<!--(v) alue-type:transient type of values --> n<!--(t) ype:persistent type of metric --> n<!-- fmt:format;show;--> n<!ELEMENT Metric(MetricFormula *, Info?)> n<!ATTLIST Metric\n i CDATA #REQUIRED\n n CDATA #REQUIRED\n es CDATA #IMPLIED\n em CDATA #IMPLIED\n ep CDATA #IMPLIED\n v(raw|final|derived-incr|derived) \"raw\\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ fmt CDATA #IMPLIED\ show (1|0) \1\\ show-percent (1|0) \1> n n<!-- MetricFormula represents derived metrics: (t)ype; (frm): formula --> n<!ELEMENT MetricFormula (Info?)> n<!ATTLIST MetricFormula\ t (combine|finalize) \finalize\\ i CDATA #IMPLIED\ frm CDATA #REQUIRED> n n<!-- Metric data, used in sections: (n)ame [from Metric]; (v)alue --> n<!ELEMENT M EMPTY> n<!ATTLIST M\ n CDATA #REQUIRED\ v CDATA #REQUIRED> n n<!-- MetricDBTable: --> n<!ELEMENT MetricDBTable (MetricDB)*> n n<!-- MetricDB: (i)d; (n)ame --> n<!-- (t)ype: persistent type of metric --> n<!-- db-glob: file glob describing files in metric db --> n<!-- db-id: id within metric db --> n<!-- db-num-metrics: number of metrics in db --> n<!-- db-header-sz: size (in bytes) of a db file header --> n<!ELEMENT MetricDB EMPTY> n<!ATTLIST MetricDB\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ db-glob CDATA #IMPLIED\ db-id CDATA #IMPLIED\ db-num-metrics CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- TraceDBTable: --> n<!ELEMENT TraceDBTable (TraceDB)> n n<!-- TraceDB: (i)d --> n<!-- db-min-time: min beginning time stamp (global) --> n<!-- db-max-time: max ending time stamp (global) --> n<!ELEMENT TraceDB EMPTY> n<!ATTLIST TraceDB\ i CDATA #REQUIRED\ db-glob CDATA #IMPLIED\ db-min-time CDATA #IMPLIED\ db-max-time CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- LoadModuleTable assigns a short name to a load module --> n<!ELEMENT LoadModuleTable (LoadModule)*> n n<!ELEMENT LoadModule (Info?)> n<!ATTLIST LoadModule\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- FileTable assigns a short name to a file --> n<!ELEMENT FileTable (File)*> n n<!ELEMENT File (Info?)> n<!ATTLIST File\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- ProcedureTable assigns a short name to a procedure --> n<!ELEMENT ProcedureTable (Procedure)*> n n<!-- Info/NV: flexible name-value pairs: (n)ame; (t)ype; (v)alue --> n<!-- f: family of the procedure (fake, root, ...)--> n<!ELEMENT Procedure (Info?)> n<!ATTLIST Procedure\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ f CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Call path profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecCallPathProfile (SecHeader, SecCallPathProfileData)> n<!ATTLIST SecCallPathProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecCallPathProfileData (PF|M)*> n<!-- Procedure frame --> n<!-- (i)d: unique identifier for cross referencing --> n<!-- (s)tatic scope id --> n<!-- (n)ame: a string or an id in ProcedureTable --> n<!-- (lm) load module: a string or an id in LoadModuleTable --> n<!-- (f)ile name: a string or an id in LoadModuleTable --> n<!-- (l)ine range: \beg-end\ (inclusive range) --> n<!-- (a)lien: whether frame is alien to enclosing P --> n<!-- (str)uct: hpcstruct node id --> n<!-- (t)ype: hpcrun node type: memory access, variable declaration, ... --> n<!-- (v)ma-range-set: \{[beg-end), [beg-end)...}\ --> n<!ELEMENT PF (PF|Pr|L|C|S|M)*> n<!ATTLIST PF\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Procedure (static): GOAL: replace with 'P' --> n<!ELEMENT Pr (Pr|L|C|S|M)*> n<!ATTLIST Pr\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ a (1|0) \0\\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Callsite (a special StatementRange) --> n<!ELEMENT C (PF|M)*> n<!ATTLIST C\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Flat profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecFlatProfile (SecHeader, SecFlatProfileData)> n<!ATTLIST SecFlatProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecFlatProfileData (LM|M)*> n<!-- Load module: (i)d; (n)ame; (v)ma-range-set --> n<!ELEMENT LM (F|P|M)*> n<!ATTLIST LM\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ v CDATA #IMPLIED> n<!-- File --> n<!ELEMENT F (P|L|S|M)*> n<!ATTLIST F\ i CDATA #IMPLIED\ n CDATA #REQUIRED> n<!-- Procedure (Note 1) --> n<!ELEMENT P (P|A|L|S|C|M)*> n<!ATTLIST P\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Alien (Note 1) --> n<!ELEMENT A (A|L|S|C|M)*> n<!ATTLIST A\ i CDATA #IMPLIED\ f CDATA #IMPLIED\ n CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Loop (Note 1,2) --> n<!ELEMENT L (A|Pr|L|S|C|M)*> n<!ATTLIST L\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ f CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Statement (Note 2) --> n<!-- (it): trace record identifier --> n<!ELEMENT S (S|M)*> n<!ATTLIST S\ i CDATA #IMPLIED\ it CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Note 1: Contained Cs may not contain PFs --> n<!-- Note 2: The 's' attribute is not used for flat profiles --> n
virtual double accumulate(Metric::IData &mdata) const
virtual double finalize(Metric::IData &mdata) const
virtual double initialize(Metric::IData &mdata) const
double srcVar(int i, const Metric::IData &mdata) const
CoefVarIncr(uint accumId, uint accum2Id, uint srcId)
AExprIncr(uint accumId, uint accum2Id, uint srcId)
double initializeStdDev(Metric::IData &mdata) const
virtual double initialize(Metric::IData &mdata) const =0
virtual double finalize(Metric::IData &mdata) const
SumIncr(uint accumId, uint srcId)
double & srcVar(int i, Metric::IData &mdata) const
virtual uint numAccum() const
MaxIncr(uint accumId, uint srcId)
static const uint npos