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>
52 allowedKeySet.insert(
"minvalue");
53 allowedKeySet.insert(
"binwidth");
54 allowedKeySet.insert(
"numbins");
55 allowedKeySet.insert(
"dumpbinsonoutput");
56 allowedKeySet.insert(
"includeoutofbounds");
60 m_minValue = statParams.
find<BinDataType>(
"minvalue", 0);
61 m_binWidth = statParams.
find<NumBinsType>(
"binwidth", 5000);
62 m_numBins = statParams.
find<NumBinsType>(
"numbins", 100);
63 m_dumpBinsOnOutput = statParams.
find<
bool>(
"dumpbinsonoutput",
true);
64 m_includeOutOfBounds = statParams.
find<
bool>(
"includeoutofbounds",
true);
71 m_itemsBinnedCount = 0;
88 if (value < getBinsMinValue()) {
92 if (value > getBinsMaxValue()) {
99 m_totalSummed += value;
100 m_totalSummedSqr += (value * value);
103 m_itemsBinnedCount++;
109 double calc1 = (double)value / (
double)m_binWidth;
110 double calc2 = floor(calc1);
111 double calc3 = m_binWidth * calc2;
112 BinDataType bin_start = (BinDataType)calc3;
115 HistoMapItr_t bin_itr = m_binsMap.find(bin_start);
118 if(bin_itr == m_binsMap.end()) {
120 m_binsMap.insert(std::pair<BinDataType, CountType>(bin_start, (CountType) 1));
129 NumBinsType getActiveBinCount()
131 return m_binsMap.size();
135 NumBinsType getNumBins()
141 NumBinsType getBinWidth()
150 CountType getBinCountByBinStart(BinDataType binStartValue)
153 HistoMapItr_t bin_itr = m_binsMap.find(binStartValue);
156 if(bin_itr == m_binsMap.end()) {
158 return (CountType) 0;
161 return m_binsMap[binStartValue];
168 BinDataType getBinsMinValue()
176 BinDataType getBinsMaxValue()
179 return (m_binWidth * m_numBins) + m_minValue - 1;
186 uint64_t getStatCollectionCount()
196 CountType getItemsBinnedCount()
199 return m_itemsBinnedCount;
206 BinDataType getValuesSummed()
208 return m_totalSummed;
215 BinDataType getValuesSquaredSummed() {
216 return m_totalSummedSqr;
219 void clearStatisticData()
override 222 m_totalSummedSqr = 0;
225 m_itemsBinnedCount = 0;
233 m_Fields.push_back(statOutput->
registerField<BinDataType>(
"BinsMinValue"));
234 m_Fields.push_back(statOutput->
registerField<BinDataType>(
"BinsMaxValue"));
235 m_Fields.push_back(statOutput->
registerField<NumBinsType>(
"BinWidth"));
236 m_Fields.push_back(statOutput->
registerField<NumBinsType>(
"TotalNumBins"));
237 m_Fields.push_back(statOutput->
registerField<BinDataType>(
"Sum"));
238 m_Fields.push_back(statOutput->
registerField<BinDataType>(
"SumSQ"));
239 m_Fields.push_back(statOutput->
registerField<NumBinsType>(
"NumActiveBins"));
240 m_Fields.push_back(statOutput->
registerField<CountType> (
"NumItemsCollected"));
241 m_Fields.push_back(statOutput->
registerField<CountType> (
"NumItemsBinned"));
243 if (
true == m_includeOutOfBounds) {
244 m_Fields.push_back(statOutput->
registerField<CountType>(
"NumOutOfBounds-MinValue"));
245 m_Fields.push_back(statOutput->
registerField<CountType>(
"NumOutOfBounds-MaxValue"));
249 if (
true == m_dumpBinsOnOutput) {
253 for (uint32_t y = 0; y < getNumBins(); y++) {
255 binLL = (y * (uint64_t)getBinWidth()) + getBinsMinValue();
256 binUL = binLL + getBinWidth() - 1;
258 std::stringstream ss;
259 ss <<
"Bin" << y <<
":" << binLL <<
"-" << binUL;
260 m_Fields.push_back(statOutput->
registerField<CountType>(ss.str().c_str()));
265 void outputStatisticData(
StatisticOutput* statOutput,
bool UNUSED(EndOfSimFlag))
override 268 statOutput->
outputField(m_Fields[x++], getBinsMinValue());
269 statOutput->
outputField(m_Fields[x++], getBinsMaxValue());
270 statOutput->
outputField(m_Fields[x++], getBinWidth());
271 statOutput->
outputField(m_Fields[x++], getNumBins());
272 statOutput->
outputField(m_Fields[x++], getValuesSummed());
273 statOutput->
outputField(m_Fields[x++], getValuesSquaredSummed());
274 statOutput->
outputField(m_Fields[x++], getActiveBinCount());
275 statOutput->
outputField(m_Fields[x++], getStatCollectionCount());
276 statOutput->
outputField(m_Fields[x++], getItemsBinnedCount());
278 if (
true == m_includeOutOfBounds) {
279 statOutput->
outputField(m_Fields[x++], m_OOBMinCount);
280 statOutput->
outputField(m_Fields[x++], m_OOBMaxCount);
284 if (
true == m_dumpBinsOnOutput) {
285 BinDataType currentBinValue = getBinsMinValue();
286 for (uint32_t y = 0; y < getNumBins(); y++) {
287 statOutput->
outputField(m_Fields[x++], getBinCountByBinStart(currentBinValue));
289 currentBinValue += getBinWidth();
296 if (mode == StatisticBase::STAT_MODE_COUNT) {
299 if (mode == StatisticBase::STAT_MODE_PERIODIC) {
307 typedef std::map<BinDataType, CountType> HistoMap_t;
310 typedef typename HistoMap_t::iterator HistoMapItr_t;
313 BinDataType m_minValue;
316 NumBinsType m_binWidth;
319 NumBinsType m_numBins;
322 CountType m_OOBMinCount;
323 CountType m_OOBMaxCount;
327 CountType m_itemsBinnedCount;
331 BinDataType m_totalSummed;
335 BinDataType m_totalSummedSqr;
338 HistoMap_t m_binsMap;
341 std::vector<uint32_t> m_Fields;
342 bool m_dumpBinsOnOutput;
343 bool m_includeOutOfBounds;
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.h:400
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:47
fieldHandle_t registerField(const char *fieldName)
Register a field to be output (templated function)
Definition: statoutput.h:85
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:202
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:85
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:294
Main component object for the simulation.
Definition: baseComponent.h:104
T 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:164
StatMode_t
Statistic collection mode.
Definition: statbase.h:65
Parameter store.
Definition: params.h:45
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:94
virtual void setCollectionCount(uint64_t newCount)
Set the current collection count to a defined value.
Definition: statbase.cc:45
void outputField(fieldHandle_t fieldHandle, int32_t data)
Output field data.
Definition: statoutput.cc:166
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:145