forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.hpp
More file actions
58 lines (49 loc) · 1.11 KB
/
launch.hpp
File metadata and controls
58 lines (49 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include "../core/async.hpp"
namespace tf {
// Function: launch_loop
template <typename P, typename Loop>
TF_FORCE_INLINE void launch_loop(
size_t N,
size_t W,
Runtime& rt,
std::atomic<size_t>& next,
P&& part,
Loop&& loop
) {
//static_assert(std::is_lvalue_reference_v<Loop>, "");
using namespace std::string_literals;
for(size_t w=0; w<W; w++) {
auto r = N - next.load(std::memory_order_relaxed);
// no more loop work to do - finished by previous async tasks
if(!r) {
break;
}
// tail optimization
if(r <= part.chunk_size() || w == W-1) {
loop();
break;
}
else {
rt.silent_async_unchecked("loop-"s + std::to_string(w), loop);
}
}
rt.join();
}
// Function: launch_loop
template <typename Loop>
TF_FORCE_INLINE void launch_loop(
size_t W,
size_t w,
Runtime& rt,
Loop&& loop
) {
using namespace std::string_literals;
if(w == W-1) {
loop();
}
else {
rt.silent_async_unchecked("loop-"s + std::to_string(w), loop);
}
}
} // end of namespace tf -----------------------------------------------------