Skip to content

Commit 455652d

Browse files
added variadic arg to precede
1 parent 274d567 commit 455652d

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

example/simple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main(){
1919
A.precede(B); // B runs after A // +---+ +-^-+
2020
A.precede(C); // C runs after A // | +---+ |
2121
B.precede(D); // D runs after B // +---->| C |-----+
22-
C.precede(D); // D runs after C // +---+
22+
C.precede(D); // D runs after C // +---+
2323

2424
tf.wait_for_all(); // block until finished
2525

taskflow/taskflow.hpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class Node {
245245
Node();
246246

247247
template <typename C>
248-
explicit Node(C&&);
248+
Node(C&&);
249249

250250
const std::string& name() const;
251251

@@ -457,21 +457,25 @@ class Task {
457457
size_t num_dependents() const;
458458

459459
Task& name(const std::string&);
460-
Task& precede(Task);
461-
Task& broadcast(std::vector<Task>&);
462-
Task& broadcast(std::initializer_list<Task>);
463-
Task& gather(std::vector<Task>&);
464-
Task& gather(std::initializer_list<Task>);
465460

466461
template <typename C>
467462
Task& work(C&&);
468-
463+
464+
template <typename... Ts>
465+
Task& precede(Ts&&...);
466+
469467
template <typename... Bs>
470468
Task& broadcast(Bs&&...);
471-
469+
470+
Task& broadcast(std::vector<Task>&);
471+
Task& broadcast(std::initializer_list<Task>);
472+
472473
template <typename... Bs>
473474
Task& gather(Bs&&...);
474475

476+
Task& gather(std::vector<Task>&);
477+
Task& gather(std::initializer_list<Task>);
478+
475479
private:
476480

477481
Node* _node {nullptr};
@@ -491,15 +495,9 @@ inline Task::Task(Node& t) : _node {&t} {
491495
inline Task::Task(const Task& rhs) : _node {rhs._node} {
492496
}
493497

494-
// Function: precede
495-
inline Task& Task::precede(Task tgt) {
496-
_node->precede(*(tgt._node));
497-
return *this;
498-
}
499-
500498
// Function: broadcast
501499
template <typename... Bs>
502-
inline Task& Task::broadcast(Bs&&... tgts) {
500+
Task& Task::broadcast(Bs&&... tgts) {
503501
(_node->precede(*(tgts._node)), ...);
504502
return *this;
505503
}
@@ -524,16 +522,23 @@ inline Task& Task::broadcast(std::initializer_list<Task> tgts) {
524522
return *this;
525523
}
526524

525+
// Function: precede
526+
template <typename... Ts>
527+
Task& Task::precede(Ts&&... tgts) {
528+
(_node->precede(*(tgts._node)), ...);
529+
return *this;
530+
}
531+
527532
// Function: gather
528533
template <typename... Bs>
529-
inline Task& Task::gather(Bs&&... tgts) {
530-
(tgts.precede(*this), ...);
534+
Task& Task::gather(Bs&&... tgts) {
535+
(tgts._node->precede(*_node), ...);
531536
return *this;
532537
}
533538

534539
// Procedure: _gather
535540
template <typename S>
536-
inline void Task::_gather(S& tgts) {
541+
void Task::_gather(S& tgts) {
537542
for(auto& from : tgts) {
538543
from._node->precede(*_node);
539544
}
@@ -1173,6 +1178,7 @@ class BasicTaskflow : public FlowBuilder {
11731178
void wait_for_all();
11741179
void wait_for_topologies();
11751180
void dump(std::ostream&) const;
1181+
void dump_topologies(std::ostream&) const;
11761182

11771183
size_t num_nodes() const;
11781184
size_t num_workers() const;
@@ -1415,7 +1421,7 @@ void BasicTaskflow<E>::_schedule(Node& node) {
14151421
_executor->emplace(*this, node);
14161422
}
14171423

1418-
// Function: dump_topology
1424+
// Function: dump_topologies
14191425
template <template <typename...> typename E>
14201426
std::string BasicTaskflow<E>::dump_topologies() const {
14211427

@@ -1428,6 +1434,14 @@ std::string BasicTaskflow<E>::dump_topologies() const {
14281434
return os.str();
14291435
}
14301436

1437+
// Function: dump_topologies
1438+
template <template <typename...> typename E>
1439+
void BasicTaskflow<E>::dump_topologies(std::ostream& os) const {
1440+
for(const auto& tpg : _topologies) {
1441+
tpg.dump(os);
1442+
}
1443+
}
1444+
14311445
// Function: dump
14321446
template <template <typename...> typename E>
14331447
void BasicTaskflow<E>::dump(std::ostream& os) const {

0 commit comments

Comments
 (0)