12 #ifndef SST_CORE_STATAPI_STATHISTOGRAM_H
13 #define SST_CORE_STATAPI_STATHISTOGRAM_H
15 #include "sst/core/sst_types.h"
16 #include "sst/core/statapi/statbase.h"
17 #include "sst/core/statapi/statoutput.h"
18 #include "sst/core/warnmacros.h"
21 namespace Statistics {
37 #define CountType uint64_t
38 #define NumBinsType uint32_t
40 template <
class BinDataType>
44 SST_ELI_DECLARE_STATISTIC_TEMPLATE(
48 SST_ELI_ELEMENT_VERSION(1, 0, 0),
49 "Track distribution of statistic across bins",
53 BaseComponent* comp,
const std::string& statName,
const std::string& statSubId,
Params& statParams) :
58 allowedKeySet.insert(
"minvalue");
59 allowedKeySet.insert(
"binwidth");
60 allowedKeySet.insert(
"numbins");
61 allowedKeySet.insert(
"dumpbinsonoutput");
62 allowedKeySet.insert(
"includeoutofbounds");
66 m_minValue = statParams.
find<BinDataType>(
"minvalue", 0);
67 m_binWidth = statParams.
find<NumBinsType>(
"binwidth", 5000);
68 m_numBins = statParams.
find<NumBinsType>(
"numbins", 100);
69 m_dumpBinsOnOutput = statParams.
find<
bool>(
"dumpbinsonoutput",
true);
70 m_includeOutOfBounds = statParams.
find<
bool>(
"includeoutofbounds",
true);
77 m_itemsBinnedCount = 0;
78 this->setCollectionCount(0);
81 this->setStatisticTypeName(
"Histogram");
94 if ( value < getBinsMinValue() ) {
98 if ( value > getBinsMaxValue() ) {
105 m_totalSummed += N * value;
106 m_totalSummedSqr += N * (value * value);
109 m_itemsBinnedCount++;
115 double calc1 = (double)value / (
double)m_binWidth;
116 double calc2 = floor(calc1);
117 double calc3 = m_binWidth * calc2;
118 BinDataType bin_start = (BinDataType)calc3;
122 HistoMapItr_t bin_itr = m_binsMap.find(bin_start);
125 if ( bin_itr == m_binsMap.end() ) {
127 m_binsMap.insert(std::pair<BinDataType, CountType>(bin_start, (CountType)N));
131 bin_itr->second += N;
139 NumBinsType getActiveBinCount() {
return m_binsMap.size(); }
142 NumBinsType getNumBins() {
return m_numBins; }
145 NumBinsType getBinWidth() {
return m_binWidth; }
151 CountType getBinCountByBinStart(BinDataType binStartValue)
154 HistoMapItr_t bin_itr = m_binsMap.find(binStartValue);
157 if ( bin_itr == m_binsMap.end() ) {
163 return m_binsMap[binStartValue];
171 BinDataType getBinsMinValue() {
return m_minValue; }
177 BinDataType getBinsMaxValue()
180 return (m_binWidth * m_numBins) + m_minValue - 1;
187 uint64_t getStatCollectionCount()
197 CountType getItemsBinnedCount()
200 return m_itemsBinnedCount;
207 BinDataType getValuesSummed() {
return m_totalSummed; }
213 BinDataType getValuesSquaredSummed() {
return m_totalSummedSqr; }
215 void clearStatisticData()
override
218 m_totalSummedSqr = 0;
221 m_itemsBinnedCount = 0;
223 this->setCollectionCount(0);
226 void registerOutputFields(StatisticFieldsOutput* statOutput)
override
229 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMinValue"));
230 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMaxValue"));
231 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"BinWidth"));
232 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"TotalNumBins"));
233 m_Fields.push_back(statOutput->registerField<BinDataType>(
"Sum"));
234 m_Fields.push_back(statOutput->registerField<BinDataType>(
"SumSQ"));
235 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"NumActiveBins"));
236 m_Fields.push_back(statOutput->registerField<CountType>(
"NumItemsCollected"));
237 m_Fields.push_back(statOutput->registerField<CountType>(
"NumItemsBinned"));
239 if (
true == m_includeOutOfBounds ) {
240 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MinValue"));
241 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MaxValue"));
245 if (
true == m_dumpBinsOnOutput ) {
249 for ( uint32_t y = 0; y < getNumBins(); y++ ) {
251 binLL = (y * (uint64_t)getBinWidth()) + getBinsMinValue();
252 binUL = binLL + getBinWidth() - 1;
254 std::stringstream ss;
255 ss <<
"Bin" << y <<
":" << binLL <<
"-" << binUL;
256 m_Fields.push_back(statOutput->registerField<CountType>(ss.str().c_str()));
261 void outputStatisticFields(StatisticFieldsOutput* statOutput,
bool UNUSED(EndOfSimFlag))
override
264 statOutput->outputField(m_Fields[x++], getBinsMinValue());
265 statOutput->outputField(m_Fields[x++], getBinsMaxValue());
266 statOutput->outputField(m_Fields[x++], getBinWidth());
267 statOutput->outputField(m_Fields[x++], getNumBins());
268 statOutput->outputField(m_Fields[x++], getValuesSummed());
269 statOutput->outputField(m_Fields[x++], getValuesSquaredSummed());
270 statOutput->outputField(m_Fields[x++], getActiveBinCount());
271 statOutput->outputField(m_Fields[x++], getStatCollectionCount());
272 statOutput->outputField(m_Fields[x++], getItemsBinnedCount());
274 if (
true == m_includeOutOfBounds ) {
275 statOutput->outputField(m_Fields[x++], m_OOBMinCount);
276 statOutput->outputField(m_Fields[x++], m_OOBMaxCount);
280 if (
true == m_dumpBinsOnOutput ) {
281 BinDataType currentBinValue = getBinsMinValue();
282 for ( uint32_t y = 0; y < getNumBins(); y++ ) {
283 statOutput->outputField(m_Fields[x++], getBinCountByBinStart(currentBinValue));
285 currentBinValue += getBinWidth();
293 case StatisticBase::STAT_MODE_COUNT:
294 case StatisticBase::STAT_MODE_PERIODIC:
295 case StatisticBase::STAT_MODE_DUMP_AT_END:
305 typedef std::map<BinDataType, CountType> HistoMap_t;
308 typedef typename HistoMap_t::iterator HistoMapItr_t;
311 BinDataType m_minValue;
314 NumBinsType m_binWidth;
317 NumBinsType m_numBins;
320 CountType m_OOBMinCount;
321 CountType m_OOBMaxCount;
325 CountType m_itemsBinnedCount;
329 BinDataType m_totalSummed;
333 BinDataType m_totalSummedSqr;
336 HistoMap_t m_binsMap;
339 std::vector<uint32_t> m_Fields;
340 bool m_dumpBinsOnOutput;
341 bool m_includeOutOfBounds;
347 #endif // SST_CORE_STATAPI_STATHISTOGRAM_H
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.cc:203
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:41
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:91
Main component object for the simulation.
Definition: baseComponent.h:49
StatMode_t
Statistic collection mode.
Definition: statbase.h:67
Parameter store.
Definition: params.h:55
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:233
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:321