MCPcopy Create free account
hub / github.com/NVIDIA/stdexec / my_main

Function my_main

examples/benchmark/common.hpp:115–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114template <class Pool, class RunThread>
115void my_main(int argc, char** argv, exec::numa_policy policy = exec::get_numa_policy())
116{
117 int nthreads = static_cast<int>(std::thread::hardware_concurrency());
118 if (argc > 1)
119 {
120 nthreads = std::atoi(argv[1]);
121 }
122 std::size_t total_scheds = 10'000'000;
123#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
124 std::vector<std::unique_ptr<char, numa_deleter>> buffers;
125#endif
126 std::optional<Pool> pool{};
127 if constexpr (std::same_as<Pool, exec::static_thread_pool>)
128 {
129 pool.emplace(nthreads, exec::bwos_params{}, policy);
130 }
131 else
132 {
133 pool.emplace(nthreads);
134 }
135 std::barrier<> barrier(nthreads + 1);
136 std::vector<std::thread> threads;
137 std::atomic<bool> stop{false};
138#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
139 std::size_t buffer_size = 2000 << 20;
140 for (std::size_t i = 0; std::cmp_less(i, nthreads); ++i)
141 {
142 exec::numa_allocator<char> alloc(policy.thread_index_to_node(i));
143 buffers.push_back(std::unique_ptr<char, numa_deleter>{
144 alloc.allocate(buffer_size),
145 numa_deleter{.size_ = buffer_size, .allocator_ = alloc}
146 });
147 }
148#endif
149 for (std::size_t i = 0; std::cmp_less(i, nthreads); ++i)
150 {
151 threads.emplace_back(RunThread{},
152 std::ref(*pool),
153 total_scheds,
154 i,
155 std::ref(barrier),
156#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
157 std::span<char>{buffers[i].get(), buffer_size},
158#endif
159 std::ref(stop),
160 policy);
161 }
162 std::size_t nRuns = 100;
163 std::size_t warmup = 1;
164 std::vector<std::chrono::steady_clock::time_point> starts(nRuns);
165 std::vector<std::chrono::steady_clock::time_point> ends(nRuns);
166 for (std::size_t i = 0; i < nRuns; ++i)
167 {
168 barrier.arrive_and_wait();
169 starts[i] = std::chrono::steady_clock::now();
170 barrier.arrive_and_wait();
171 ends[i] = std::chrono::steady_clock::now();
172 if (i < warmup)

Callers

nothing calls this directly

Calls 8

get_numa_policyFunction · 0.85
compute_perfFunction · 0.85
emplaceMethod · 0.45
thread_index_to_nodeMethod · 0.45
push_backMethod · 0.45
allocateMethod · 0.45
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected