00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _H_SST_CORE_ACCUMULATOR_STATISTIC_
00014 #define _H_SST_CORE_ACCUMULATOR_STATISTIC_
00015
00016 #include <sst/core/sst_types.h>
00017 #include <sst/core/serialization.h>
00018
00019 #include <sst/core/statapi/statbase.h>
00020
00021 namespace SST {
00022 namespace Statistics {
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 template <typename NumberBase>
00043 class AccumulatorStatistic : public Statistic<NumberBase>
00044 {
00045 private:
00046 friend class SST::Simulation;
00047
00048 AccumulatorStatistic(Component* comp, std::string& statName, std::string& statSubId, Params& statParams)
00049 : Statistic<NumberBase>(comp, statName, statSubId, statParams)
00050 {
00051 m_sum = 0;
00052 m_sum_sq = 0;
00053
00054
00055 this->setStatisticTypeName("Accumulator");
00056 }
00057
00058 ~AccumulatorStatistic() {}
00059
00060 protected:
00061
00062
00063
00064
00065 void addData_impl(NumberBase value)
00066 {
00067 m_sum += value;
00068 m_sum_sq += (value * value);
00069 }
00070
00071 private:
00072
00073
00074
00075
00076 NumberBase getSum()
00077 {
00078 return m_sum;
00079 }
00080
00081
00082
00083
00084
00085 NumberBase getSumSquared()
00086 {
00087 return m_sum_sq;
00088 }
00089
00090
00091
00092
00093
00094 NumberBase getArithmeticMean()
00095 {
00096 uint64_t count = getCount();
00097 return (count > 0) ? (m_sum / (NumberBase) count) : 0;
00098 }
00099
00100
00101
00102
00103
00104 NumberBase getVariance()
00105 {
00106 uint64_t count = getCount();
00107 return (count > 0) ? (m_sum_sq * count) - (m_sum * m_sum) : 0;
00108 }
00109
00110
00111
00112
00113
00114 NumberBase getStandardDeviation()
00115 {
00116 return (NumberBase) std::sqrt( (double) getVariance() );
00117 }
00118
00119
00120
00121
00122
00123 uint64_t getCount()
00124 {
00125 return this->getCollectionCount();
00126 }
00127
00128 void clearStatisticData()
00129 {
00130 m_sum = 0;
00131 m_sum_sq =0;
00132 this->setCollectionCount(0);
00133 }
00134
00135 void registerOutputFields(StatisticOutput* statOutput)
00136 {
00137 Field1 = statOutput->registerField<NumberBase>("Sum");
00138 Field2 = statOutput->registerField<NumberBase>("SumSQ");
00139 Field3 = statOutput->registerField<uint64_t> ("Count");
00140 }
00141
00142 void outputStatisticData(StatisticOutput* statOutput, bool EndOfSimFlag)
00143 {
00144 statOutput->outputField(Field1, m_sum);
00145 statOutput->outputField(Field2, m_sum_sq);
00146 statOutput->outputField(Field3, getCount());
00147 }
00148
00149 bool isStatModeSupported(StatisticBase::StatMode_t mode) const
00150 {
00151 if (mode == StatisticBase::STAT_MODE_COUNT) {
00152 return true;
00153 }
00154 if (mode == StatisticBase::STAT_MODE_PERIODIC) {
00155 return true;
00156 }
00157 return false;
00158 }
00159
00160 private:
00161 NumberBase m_sum;
00162 NumberBase m_sum_sq;
00163
00164 StatisticOutput::fieldHandle_t Field1, Field2, Field3;
00165 friend class boost::serialization::access;
00166 template<class Archive>
00167 void serialize(Archive & ar, const unsigned int version)
00168 {
00169 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Statistic<NumberBase>);
00170 ar & BOOST_SERIALIZATION_NVP(m_sum);
00171 ar & BOOST_SERIALIZATION_NVP(m_sum_sq);
00172 }
00173 };
00174
00175 }
00176 }
00177
00178
00179
00180 #endif