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 += value;
108 m_totalSummedSqr += (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) 1));
137 NumBinsType getActiveBinCount()
139 return m_binsMap.size();
143 NumBinsType getNumBins()
149 NumBinsType getBinWidth()
158 CountType getBinCountByBinStart(BinDataType binStartValue)
161 HistoMapItr_t bin_itr = m_binsMap.find(binStartValue);
164 if(bin_itr == m_binsMap.end()) {
166 return (CountType) 0;
169 return m_binsMap[binStartValue];
176 BinDataType getBinsMinValue()
184 BinDataType getBinsMaxValue()
187 return (m_binWidth * m_numBins) + m_minValue - 1;
194 uint64_t getStatCollectionCount()
204 CountType getItemsBinnedCount()
207 return m_itemsBinnedCount;
214 BinDataType getValuesSummed()
216 return m_totalSummed;
223 BinDataType getValuesSquaredSummed() {
224 return m_totalSummedSqr;
227 void clearStatisticData()
override
230 m_totalSummedSqr = 0;
233 m_itemsBinnedCount = 0;
235 this->setCollectionCount(0);
238 void registerOutputFields(StatisticOutput* statOutput)
override
241 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMinValue"));
242 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMaxValue"));
243 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"BinWidth"));
244 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"TotalNumBins"));
245 m_Fields.push_back(statOutput->registerField<BinDataType>(
"Sum"));
246 m_Fields.push_back(statOutput->registerField<BinDataType>(
"SumSQ"));
247 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"NumActiveBins"));
248 m_Fields.push_back(statOutput->registerField<CountType> (
"NumItemsCollected"));
249 m_Fields.push_back(statOutput->registerField<CountType> (
"NumItemsBinned"));
251 if (
true == m_includeOutOfBounds) {
252 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MinValue"));
253 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MaxValue"));
257 if (
true == m_dumpBinsOnOutput) {
261 for (uint32_t y = 0; y < getNumBins(); y++) {
263 binLL = (y * (uint64_t)getBinWidth()) + getBinsMinValue();
264 binUL = binLL + getBinWidth() - 1;
266 std::stringstream ss;
267 ss <<
"Bin" << y <<
":" << binLL <<
"-" << binUL;
268 m_Fields.push_back(statOutput->registerField<CountType>(ss.str().c_str()));
273 void outputStatisticData(StatisticOutput* statOutput,
bool UNUSED(EndOfSimFlag))
override
276 statOutput->outputField(m_Fields[x++], getBinsMinValue());
277 statOutput->outputField(m_Fields[x++], getBinsMaxValue());
278 statOutput->outputField(m_Fields[x++], getBinWidth());
279 statOutput->outputField(m_Fields[x++], getNumBins());
280 statOutput->outputField(m_Fields[x++], getValuesSummed());
281 statOutput->outputField(m_Fields[x++], getValuesSquaredSummed());
282 statOutput->outputField(m_Fields[x++], getActiveBinCount());
283 statOutput->outputField(m_Fields[x++], getStatCollectionCount());
284 statOutput->outputField(m_Fields[x++], getItemsBinnedCount());
286 if (
true == m_includeOutOfBounds) {
287 statOutput->outputField(m_Fields[x++], m_OOBMinCount);
288 statOutput->outputField(m_Fields[x++], m_OOBMaxCount);
292 if (
true == m_dumpBinsOnOutput) {
293 BinDataType currentBinValue = getBinsMinValue();
294 for (uint32_t y = 0; y < getNumBins(); y++) {
295 statOutput->outputField(m_Fields[x++], getBinCountByBinStart(currentBinValue));
297 currentBinValue += getBinWidth();
304 if (mode == StatisticBase::STAT_MODE_COUNT) {
307 if (mode == StatisticBase::STAT_MODE_PERIODIC) {
315 typedef std::map<BinDataType, CountType> HistoMap_t;
318 typedef typename HistoMap_t::iterator HistoMapItr_t;
321 BinDataType m_minValue;
324 NumBinsType m_binWidth;
327 NumBinsType m_numBins;
330 CountType m_OOBMinCount;
331 CountType m_OOBMaxCount;
335 CountType m_itemsBinnedCount;
339 BinDataType m_totalSummed;
343 BinDataType m_totalSummedSqr;
346 HistoMap_t m_binsMap;
349 std::vector<uint32_t> m_Fields;
350 bool m_dumpBinsOnOutput;
351 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:238
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:149
Holder of data grouped into pre-determined width bins.
Definition: stathistogram.h:43
void addData_impl(BinDataType value) override
Adds a new value to the histogram.
Definition: stathistogram.h:93
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:43
Main component object for the simulation.
Definition: baseComponent.h:52
StatMode_t
Statistic collection mode.
Definition: statbase.h:67
Parameter store.
Definition: params.h:45
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:172