File indexing completed on 2024-04-06 12:13:15
0001 #include "FWCore/Utilities/interface/RunningAverage.h"
0002
0003 namespace {
0004
0005 edm::RunningAverage localRA;
0006
0007 }
0008
0009 #include "oneapi/tbb/parallel_for.h"
0010 #include "oneapi/tbb/task_arena.h"
0011 #include "oneapi/tbb/global_control.h"
0012 #include <iostream>
0013 #include <vector>
0014 #include <atomic>
0015 #include <random>
0016 #include <algorithm>
0017 #include <type_traits>
0018
0019 namespace test_average {
0020 namespace running_average {
0021 int test() {
0022 oneapi::tbb::global_control control(
0023 oneapi::tbb::global_control::max_allowed_parallelism,
0024 oneapi::tbb::this_task_arena::max_concurrency());
0025
0026
0027 std::mt19937 e2;
0028 std::normal_distribution<> normal_dist(1000., 200.);
0029
0030 thread_local std::vector<float> v;
0031
0032 int kk = 0;
0033
0034 int n = 2000;
0035
0036 int res[n];
0037 int qq[n];
0038 for (auto& y : qq)
0039 y = std::max(0., normal_dist(e2));
0040
0041 auto theLoop = [&](int i) {
0042 kk++;
0043 v.reserve(res[i] = localRA.upper());
0044 v.resize(qq[i]);
0045 localRA.update(v.size());
0046 decltype(v) t;
0047 swap(v, t);
0048 };
0049
0050 oneapi::tbb::parallel_for(oneapi::tbb::blocked_range<size_t>(0, n),
0051 [&](const oneapi::tbb::blocked_range<size_t>& r) {
0052 for (size_t i = r.begin(); i < r.end(); ++i)
0053 theLoop(i);
0054 });
0055
0056 auto mm = std::max_element(res, res + n);
0057 std::cout << kk << ' ' << localRA.m_curr << ' ' << localRA.mean() << std::endl;
0058 for (auto& i : localRA.m_buffer)
0059 std::cout << i << ' ';
0060 std::cout << std::endl;
0061 std::cout << std::accumulate(res, res + n, 0) / n << ' ' << *std::min_element(res + 16, res + n) << ',' << *mm
0062 << std::endl;
0063
0064 return 0;
0065 }
0066 }
0067 }
0068
0069 int main() { return ::test_average::running_average::test(); }