MCPcopy Create free account
hub / github.com/NVIDIA/stdexec / operator()

Method operator()

examples/benchmark/static_thread_pool_nested.cpp:23–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21struct RunThread
22{
23 void operator()(exec::static_thread_pool& pool,
24 std::size_t total_scheds,
25 std::size_t tid,
26 std::barrier<>& barrier,
27#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
28 std::span<char> buffer,
29#endif
30 std::atomic<bool>& stop,
31 exec::numa_policy numa)
32 {
33 int numa_node = numa.thread_index_to_node(tid);
34 numa.bind_to_node(numa_node);
35 auto scheduler = pool.get_scheduler();
36 std::mutex mut;
37 std::condition_variable cv;
38 while (true)
39 {
40 barrier.arrive_and_wait();
41 if (stop.load())
42 {
43 break;
44 }
45#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
46 pmr::monotonic_buffer_resource resource{buffer.data(),
47 buffer.size(),
48 pmr::null_memory_resource()};
49 pmr::polymorphic_allocator<char> alloc(&resource);
50 auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism());
51 std::size_t scheds = end - start;
52 std::atomic<std::size_t> counter{scheds};
53 auto env = stdexec::prop{stdexec::get_allocator, alloc};
54 stdexec::sync_wait(stdexec::schedule(scheduler)
55 | stdexec::then(
56 [&]
57 {
58 auto nested_scheduler = pool.get_scheduler();
59 while (scheds)
60 {
61 exec::start_detached(stdexec::schedule(nested_scheduler)
62 | stdexec::then(
63 [&]
64 {
65 auto prev = counter.fetch_sub(1);
66 if (prev == 1)
67 {
68 std::lock_guard lock{mut};
69 cv.notify_one();
70 }
71 }),
72 env);
73 --scheds;
74 }
75 }));
76#else
77 auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism());
78 std::size_t scheds = end - start;
79 std::atomic<std::size_t> counter{scheds};
80 stdexec::sync_wait(stdexec::schedule(scheduler)

Callers

nothing calls this directly

Calls 10

even_shareFunction · 0.85
thenFunction · 0.85
scheduleFunction · 0.50
thread_index_to_nodeMethod · 0.45
bind_to_nodeMethod · 0.45
get_schedulerMethod · 0.45
loadMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
available_parallelismMethod · 0.45

Tested by

no test coverage detected