13 #ifndef _H_SST_CORE_HISTOGRAM_STATISTIC_
14 #define _H_SST_CORE_HISTOGRAM_STATISTIC_
16 #include "sst/core/sst_types.h"
17 #include "sst/core/warnmacros.h"
19 #include "sst/core/statapi/statbase.h"
20 #include "sst/core/statapi/statoutput.h"
23 namespace Statistics {
39 #define CountType uint64_t
40 #define NumBinsType uint32_t
42 template<
class BinDataType>
46 SST_ELI_DECLARE_STATISTIC_TEMPLATE(
50 SST_ELI_ELEMENT_VERSION(1,0,0),
51 "Track distribution of statistic across bins",
55 const std::string& statSubId,
Params& statParams) :
60 allowedKeySet.insert(
"minvalue");
61 allowedKeySet.insert(
"binwidth");
62 allowedKeySet.insert(
"numbins");
63 allowedKeySet.insert(
"dumpbinsonoutput");
64 allowedKeySet.insert(
"includeoutofbounds");
68 m_minValue = statParams.
find<BinDataType>(
"minvalue", 0);
69 m_binWidth = statParams.
find<NumBinsType>(
"binwidth", 5000);
70 m_numBins = statParams.
find<NumBinsType>(
"numbins", 100);
71 m_dumpBinsOnOutput = statParams.
find<
bool>(
"dumpbinsonoutput",
true);
72 m_includeOutOfBounds = statParams.
find<
bool>(
"includeoutofbounds",
true);
79 m_itemsBinnedCount = 0;
80 this->setCollectionCount(0);
83 this->setStatisticTypeName(
"Histogram");
96 if (value < getBinsMinValue()) {
100 if (value > getBinsMaxValue()) {
107 m_totalSummed += N*value;
108 m_totalSummedSqr += N*(value * value);
111 m_itemsBinnedCount++;
117 double calc1 = (double)value / (
double)m_binWidth;
118 double calc2 = floor(calc1);
119 double calc3 = m_binWidth * calc2;
120 BinDataType bin_start = (BinDataType)calc3;
123 HistoMapItr_t bin_itr = m_binsMap.find(bin_start);
126 if(bin_itr == m_binsMap.end()) {
128 m_binsMap.insert(std::pair<BinDataType, CountType>(bin_start, (CountType) N));
131 bin_itr->second += N;
135 void addData_impl(BinDataType value)
override {
141 NumBinsType getActiveBinCount()
143 return m_binsMap.size();
147 NumBinsType getNumBins()
153 NumBinsType getBinWidth()
162 CountType getBinCountByBinStart(BinDataType binStartValue)
165 HistoMapItr_t bin_itr = m_binsMap.find(binStartValue);
168 if(bin_itr == m_binsMap.end()) {
170 return (CountType) 0;
173 return m_binsMap[binStartValue];
180 BinDataType getBinsMinValue()
188 BinDataType getBinsMaxValue()
191 return (m_binWidth * m_numBins) + m_minValue - 1;
198 uint64_t getStatCollectionCount()
208 CountType getItemsBinnedCount()
211 return m_itemsBinnedCount;
218 BinDataType getValuesSummed()
220 return m_totalSummed;
227 BinDataType getValuesSquaredSummed() {
228 return m_totalSummedSqr;
231 void clearStatisticData()
override
234 m_totalSummedSqr = 0;
237 m_itemsBinnedCount = 0;
239 this->setCollectionCount(0);
242 void registerOutputFields(StatisticFieldsOutput* statOutput)
override
245 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMinValue"));
246 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMaxValue"));
247 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"BinWidth"));
248 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"TotalNumBins"));
249 m_Fields.push_back(statOutput->registerField<BinDataType>(
"Sum"));
250 m_Fields.push_back(statOutput->registerField<BinDataType>(
"SumSQ"));
251 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"NumActiveBins"));
252 m_Fields.push_back(statOutput->registerField<CountType> (
"NumItemsCollected"));
253 m_Fields.push_back(statOutput->registerField<CountType> (
"NumItemsBinned"));
255 if (
true == m_includeOutOfBounds) {
256 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MinValue"));
257 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MaxValue"));
261 if (
true == m_dumpBinsOnOutput) {
265 for (uint32_t y = 0; y < getNumBins(); y++) {
267 binLL = (y * (uint64_t)getBinWidth()) + getBinsMinValue();
268 binUL = binLL + getBinWidth() - 1;
270 std::stringstream ss;
271 ss <<
"Bin" << y <<
":" << binLL <<
"-" << binUL;
272 m_Fields.push_back(statOutput->registerField<CountType>(ss.str().c_str()));
277 void outputStatisticFields(StatisticFieldsOutput* statOutput,
bool UNUSED(EndOfSimFlag))
override
280 statOutput->outputField(m_Fields[x++], getBinsMinValue());
281 statOutput->outputField(m_Fields[x++], getBinsMaxValue());
282 statOutput->outputField(m_Fields[x++], getBinWidth());
283 statOutput->outputField(m_Fields[x++], getNumBins());
284 statOutput->outputField(m_Fields[x++], getValuesSummed());
285 statOutput->outputField(m_Fields[x++], getValuesSquaredSummed());
286 statOutput->outputField(m_Fields[x++], getActiveBinCount());
287 statOutput->outputField(m_Fields[x++], getStatCollectionCount());
288 statOutput->outputField(m_Fields[x++], getItemsBinnedCount());
290 if (
true == m_includeOutOfBounds) {
291 statOutput->outputField(m_Fields[x++], m_OOBMinCount);
292 statOutput->outputField(m_Fields[x++], m_OOBMaxCount);
296 if (
true == m_dumpBinsOnOutput) {
297 BinDataType currentBinValue = getBinsMinValue();
298 for (uint32_t y = 0; y < getNumBins(); y++) {
299 statOutput->outputField(m_Fields[x++], getBinCountByBinStart(currentBinValue));
301 currentBinValue += getBinWidth();
309 case StatisticBase::STAT_MODE_COUNT:
310 case StatisticBase::STAT_MODE_PERIODIC:
311 case StatisticBase::STAT_MODE_DUMP_AT_END:
321 typedef std::map<BinDataType, CountType> HistoMap_t;
324 typedef typename HistoMap_t::iterator HistoMapItr_t;
327 BinDataType m_minValue;
330 NumBinsType m_binWidth;
333 NumBinsType m_numBins;
336 CountType m_OOBMinCount;
337 CountType m_OOBMaxCount;
341 CountType m_itemsBinnedCount;
345 BinDataType m_totalSummed;
349 BinDataType m_totalSummedSqr;
352 HistoMap_t m_binsMap;
355 std::vector<uint32_t> m_Fields;
356 bool m_dumpBinsOnOutput;
357 bool m_includeOutOfBounds;
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.cc:179
std::enable_if< not std::is_same< std::string, T >::value, T >::type find(const std::string &k, T default_value, bool &found) const
Find a Parameter value in the set, and return its value as a type T.
Definition: params.h:237
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:155
Holder of data grouped into pre-determined width bins.
Definition: stathistogram.h:43
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:42
void addData_impl_Ntimes(uint64_t N, BinDataType value) override
Adds a new value to the histogram.
Definition: stathistogram.h:93
Main component object for the simulation.
Definition: baseComponent.h:52
StatMode_t
Statistic collection mode.
Definition: statbase.h:68
Parameter store.
Definition: params.h:44
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:171