Skip to content

Commit 808c38b

Browse files
committed
fix vs bug
1>parallel_for.cpp 1>D:\taskflow\taskflow/algorithm/for_each.hpp(62,1): fatal error C1001: Internal compiler error. 1>(compiler file 'D:\a\_work\1\s\src\vctools\Compiler\CxxFE\sl\p1\c\lambdas.cpp', line 546) 1> To work around this problem, try simplifying or changing the program near the locations listed above. 1>If possible please provide a repro here: https://developercommunity.visualstudio.com 1>Please choose the Technical Support command on the Visual C++ 1> Help menu, or open the Technical Support help file for more information 1>D:\taskflow\taskflow/algorithm/for_each.hpp(165): message : see reference to function template instantiation 'auto tf::make_for_each_task<B,E,C,P>(B,E,C,P)' being compiled 1> with 1> [ 1> B=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>, 1> E=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>, 1> C=for_each::<lambda_891c819562d1c754b7032e9ff9e1d9ce>, 1> P=tf::DefaultPartitioner 1> ] 1>D:\taskflow\examples\parallel_for.cpp(19): message : see reference to function template instantiation 'tf::Task tf::FlowBuilder::for_each<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,for_each::<lambda_891c819562d1c754b7032e9ff9e1d9ce>,tf::DefaultPartitioner>(B,E,C,P)' being compiled 1> with 1> [ 1> _Ty=int, 1> B=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>, 1> E=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>, 1> C=for_each::<lambda_891c819562d1c754b7032e9ff9e1d9ce>, 1> P=tf::DefaultPartitioner 1> ] 1>Done building project "parallel_for.vcxproj" -- FAILED.
1 parent 39c4b6d commit 808c38b

File tree

6 files changed

+110
-76
lines changed

6 files changed

+110
-76
lines changed

taskflow/algorithm/find.hpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ TF_FORCE_INLINE auto make_find_if_task(
8080

8181
// only myself - no need to spawn another graph
8282
if(W <= 1 || N <= part.chunk_size()) {
83-
TF_MAKE_LOOP_TASK(
83+
TF_MAKE_LOOP_TASK( [&](){
8484
result = std::find_if(beg, end, predicate);
85+
}, part
8586
);
8687
return;
8788
}
@@ -104,14 +105,14 @@ TF_FORCE_INLINE auto make_find_if_task(
104105
launch_loop(W, w, rt,
105106
[N, W, curr_b, chunk_size, beg, &predicate, &offset, &part]
106107
() mutable {
107-
TF_MAKE_LOOP_TASK(
108+
TF_MAKE_LOOP_TASK( [&](){
108109
part.loop_until(N, W, curr_b, chunk_size,
109110
[&, prev_e=size_t{0}](size_t part_b, size_t part_e) mutable {
110111
return detail::find_if_loop(
111112
offset, beg, prev_e, part_b, part_e, predicate
112113
);
113114
}
114-
);
115+
); }, part
115116
);
116117
}
117118
);
@@ -124,14 +125,14 @@ TF_FORCE_INLINE auto make_find_if_task(
124125
std::atomic<size_t> next(0);
125126
launch_loop(N, W, rt, next, part,
126127
[N, W, beg, &predicate, &offset, &next, &part] () mutable {
127-
TF_MAKE_LOOP_TASK(
128+
TF_MAKE_LOOP_TASK([&](){
128129
part.loop_until(N, W, next,
129130
[&, prev_e=size_t{0}](size_t curr_b, size_t curr_e) mutable {
130131
return detail::find_if_loop(
131132
offset, beg, prev_e, curr_b, curr_e, predicate
132133
);
133134
}
134-
);
135+
); }, part
135136
);
136137
}
137138
);
@@ -163,9 +164,9 @@ TF_FORCE_INLINE auto make_find_if_not_task(
163164

164165
// only myself - no need to spawn another graph
165166
if(W <= 1 || N <= part.chunk_size()) {
166-
TF_MAKE_LOOP_TASK(
167+
TF_MAKE_LOOP_TASK([&](){
167168
result = std::find_if_not(beg, end, predicate);
168-
);
169+
}, part);
169170
return;
170171
}
171172

@@ -186,14 +187,14 @@ TF_FORCE_INLINE auto make_find_if_not_task(
186187

187188
launch_loop(W, w, rt,
188189
[N, W, curr_b, chunk_size, beg, &predicate, &offset, &part] () mutable {
189-
TF_MAKE_LOOP_TASK(
190+
TF_MAKE_LOOP_TASK([&](){
190191
part.loop_until(N, W, curr_b, chunk_size,
191192
[&, prev_e=size_t{0}](size_t part_b, size_t part_e) mutable {
192193
return detail::find_if_not_loop(
193194
offset, beg, prev_e, part_b, part_e, predicate
194195
);
195196
}
196-
);
197+
); }, part
197198
);
198199
}
199200
);
@@ -206,14 +207,14 @@ TF_FORCE_INLINE auto make_find_if_not_task(
206207
std::atomic<size_t> next(0);
207208
launch_loop(N, W, rt, next, part,
208209
[N, W, beg, &predicate, &offset, &next, &part] () mutable {
209-
TF_MAKE_LOOP_TASK(
210+
TF_MAKE_LOOP_TASK([&](){
210211
part.loop_until(N, W, next,
211212
[&, prev_e=size_t{0}](size_t curr_b, size_t curr_e) mutable {
212213
return detail::find_if_not_loop(
213214
offset, beg, prev_e, curr_b, curr_e, predicate
214215
);
215216
}
216-
);
217+
);}, part
217218
);
218219
}
219220
);
@@ -245,8 +246,9 @@ TF_FORCE_INLINE auto make_min_element_task(
245246

246247
// only myself - no need to spawn another graph
247248
if(W <= 1 || N <= part.chunk_size()) {
248-
TF_MAKE_LOOP_TASK(
249+
TF_MAKE_LOOP_TASK([&](){
249250
result = std::min_element(beg, end, comp);
251+
}, part
250252
);
251253
return;
252254
}
@@ -274,7 +276,7 @@ TF_FORCE_INLINE auto make_min_element_task(
274276

275277
launch_loop(W, w, rt,
276278
[beg, curr_b, N, W, chunk_size, &comp, &mutex, &result, &part] () mutable {
277-
TF_MAKE_LOOP_TASK(
279+
TF_MAKE_LOOP_TASK([&](){
278280

279281
std::advance(beg, curr_b);
280282

@@ -315,6 +317,7 @@ TF_FORCE_INLINE auto make_min_element_task(
315317
if(comp(*smallest, *result)) {
316318
result = smallest;
317319
}
320+
}, part
318321
);
319322
});
320323
}
@@ -326,7 +329,7 @@ TF_FORCE_INLINE auto make_min_element_task(
326329
launch_loop(N, W, rt, next, part,
327330
[beg, N, W, &next, &comp, &mutex, &result, &part] () mutable {
328331

329-
TF_MAKE_LOOP_TASK(
332+
TF_MAKE_LOOP_TASK([&](){
330333

331334
// pre-reduce
332335
size_t s0 = next.fetch_add(2, std::memory_order_relaxed);
@@ -368,7 +371,7 @@ TF_FORCE_INLINE auto make_min_element_task(
368371
if(comp(*smallest, *result)) {
369372
result = smallest;
370373
}
371-
374+
}, part
372375
);
373376
}
374377
);
@@ -397,8 +400,9 @@ TF_FORCE_INLINE auto make_max_element_task(
397400

398401
// only myself - no need to spawn another graph
399402
if(W <= 1 || N <= part.chunk_size()) {
400-
TF_MAKE_LOOP_TASK(
403+
TF_MAKE_LOOP_TASK([&](){
401404
result = std::max_element(beg, end, comp);
405+
}, part
402406
);
403407
return;
404408
}
@@ -428,7 +432,7 @@ TF_FORCE_INLINE auto make_max_element_task(
428432
[beg, curr_b, N, W, chunk_size, &comp, &mutex, &result, &part] () mutable {
429433

430434
TF_MAKE_LOOP_TASK(
431-
435+
[&](){
432436
std::advance(beg, curr_b);
433437

434438
if(N - curr_b == 1) {
@@ -468,7 +472,7 @@ TF_FORCE_INLINE auto make_max_element_task(
468472
if(comp(*result, *largest)) {
469473
result = largest;
470474
}
471-
475+
}, part
472476
);
473477
});
474478
}
@@ -481,7 +485,7 @@ TF_FORCE_INLINE auto make_max_element_task(
481485
[beg, N, W, &next, &comp, &mutex, &result, &part] () mutable {
482486

483487
TF_MAKE_LOOP_TASK(
484-
488+
[&](){
485489
// pre-reduce
486490
size_t s0 = next.fetch_add(2, std::memory_order_relaxed);
487491

@@ -522,7 +526,7 @@ TF_FORCE_INLINE auto make_max_element_task(
522526
if(comp(*result, *largest)) {
523527
result = largest;
524528
}
525-
529+
}, part
526530
);
527531
}
528532
);

taskflow/algorithm/for_each.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ TF_FORCE_INLINE auto make_for_each_task(B b, E e, C c, P part = P()) {
2323

2424
// only myself - no need to spawn another graph
2525
if(W <= 1 || N <= part.chunk_size()) {
26-
TF_MAKE_LOOP_TASK(
26+
TF_MAKE_LOOP_TASK([&](){
2727
std::for_each(beg, end, c);
28+
}, part
2829
);
2930
return;
3031
}
@@ -39,7 +40,7 @@ TF_FORCE_INLINE auto make_for_each_task(B b, E e, C c, P part = P()) {
3940
for(size_t w=0, curr_b=0; w<W && curr_b < N; ++w, curr_b += chunk_size) {
4041
chunk_size = part.adjusted_chunk_size(N, W, w);
4142
launch_loop(W, w, rt, [=, &c, &part] () mutable {
42-
TF_MAKE_LOOP_TASK(
43+
TF_MAKE_LOOP_TASK([&](){
4344
part.loop(N, W, curr_b, chunk_size,
4445
[&, prev_e=size_t{0}](size_t part_b, size_t part_e) mutable {
4546
std::advance(beg, part_b - prev_e);
@@ -48,7 +49,7 @@ TF_FORCE_INLINE auto make_for_each_task(B b, E e, C c, P part = P()) {
4849
}
4950
prev_e = part_e;
5051
}
51-
);
52+
); }, part
5253
);
5354
});
5455
}
@@ -59,7 +60,7 @@ TF_FORCE_INLINE auto make_for_each_task(B b, E e, C c, P part = P()) {
5960
else {
6061
std::atomic<size_t> next(0);
6162
launch_loop(N, W, rt, next, part, [=, &c, &next, &part] () mutable {
62-
TF_MAKE_LOOP_TASK(
63+
TF_MAKE_LOOP_TASK([&](){
6364
part.loop(N, W, next,
6465
[&, prev_e=size_t{0}](size_t part_b, size_t part_e) mutable {
6566
std::advance(beg, part_b - prev_e);
@@ -68,7 +69,7 @@ TF_FORCE_INLINE auto make_for_each_task(B b, E e, C c, P part = P()) {
6869
}
6970
prev_e = part_e;
7071
}
71-
);
72+
); }, part
7273
);
7374
});
7475
}
@@ -102,10 +103,11 @@ TF_FORCE_INLINE auto make_for_each_index_task(B b, E e, S s, C c, P part = P()){
102103

103104
// only myself - no need to spawn another graph
104105
if(W <= 1 || N <= part.chunk_size()) {
105-
TF_MAKE_LOOP_TASK(
106+
TF_MAKE_LOOP_TASK([&](){
106107
for(size_t x=0; x<N; x++, beg+=inc) {
107108
c(beg);
108109
}
110+
}, part
109111
);
110112
return;
111113
}
@@ -120,15 +122,15 @@ TF_FORCE_INLINE auto make_for_each_index_task(B b, E e, S s, C c, P part = P()){
120122
for(size_t w=0, curr_b=0; w<W && curr_b < N; ++w, curr_b += chunk_size) {
121123
chunk_size = part.adjusted_chunk_size(N, W, w);
122124
launch_loop(W, w, rt, [=, &c, &part] () mutable {
123-
TF_MAKE_LOOP_TASK(
125+
TF_MAKE_LOOP_TASK([&](){
124126
part.loop(N, W, curr_b, chunk_size,
125127
[&](size_t part_b, size_t part_e) {
126128
auto idx = static_cast<B_t>(part_b) * inc + beg;
127129
for(size_t x=part_b; x<part_e; x++, idx += inc) {
128130
c(idx);
129131
}
130132
}
131-
);
133+
); }, part
132134
);
133135
});
134136
}
@@ -139,15 +141,15 @@ TF_FORCE_INLINE auto make_for_each_index_task(B b, E e, S s, C c, P part = P()){
139141
else {
140142
std::atomic<size_t> next(0);
141143
launch_loop(N, W, rt, next, part, [=, &c, &next, &part] () mutable {
142-
TF_MAKE_LOOP_TASK(
144+
TF_MAKE_LOOP_TASK([&](){
143145
part.loop(N, W, next,
144146
[&](size_t part_b, size_t part_e) {
145147
auto idx = static_cast<B_t>(part_b) * inc + beg;
146148
for(size_t x=part_b; x<part_e; x++, idx += inc) {
147149
c(idx);
148150
}
149151
}
150-
);
152+
); }, part
151153
);
152154
});
153155
}

taskflow/algorithm/launch.hpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44

55
namespace tf {
66

7-
#define TF_MAKE_LOOP_TASK(code_block) \
8-
if constexpr(std::is_same_v<typename std::decay_t<P>::closure_wrapper_type, DefaultClosureWrapper>) { \
9-
code_block \
10-
} \
11-
else { \
12-
std::invoke(part.closure_wrapper(), [&](){ code_block }); \
13-
}
7+
template<typename TP>
8+
constexpr bool is_default_wrapper_v = std::is_same_v<typename std::decay_t<TP>::closure_wrapper_type, DefaultClosureWrapper>;
9+
10+
template<typename TP , typename OP, std::enable_if_t<is_default_wrapper_v<TP>, bool> = true>
11+
void CodeBlockInvoker(OP op, [[maybe_unused]] TP _part)
12+
{
13+
op();
14+
}
15+
16+
template<typename TP , typename OP, std::enable_if_t<!is_default_wrapper_v<TP>, bool> = true>
17+
void CodeBlockInvoker(OP op, [[maybe_unused]] TP _part)
18+
{
19+
std::invoke(_part.closure_wrapper(), op); \
20+
};
21+
22+
template<typename Op, typename TP>
23+
void TF_MAKE_LOOP_TASK(Op op, TP tp)
24+
{
25+
CodeBlockInvoker([&](){ op(); }, tp);
26+
}
1427

1528
// Function: launch_loop
1629
template <typename P, typename Loop>

0 commit comments

Comments
 (0)