FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

added cache · tornadocean/cpp-taskflow@6b3aab6 · GitHub

Repository navigation

Commit 6b3aab6

Browse files
added cache
1 parent 9d4bcb1 commit 6b3aab6

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

‎awesome-parallel-computing.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ All the lists in this page are either in alphabetical order or chronological ord
7373

7474
- [C++ Concurrency in Action: Practical Multithreading](https://www.manning.com/books/c-plus-plus-concurrency-in-action) - Anthony Williams 2012
7575
- [The Art of Multiprocessor Programming](https://www.amazon.com/Art-Multiprocessor-Programming-Revised-Reprint/dp/0123973376/ref=sr_1_1?ie=UTF8&qid=1438003865&sr=8-1&keywords=maurice+herlihy) - Maurice Herlihy 2012
76+
- [Parallel Computing: Theory and Practice](http://www.cs.cmu.edu/afs/cs/academic/class/15210-f15/www/tapp.html#ch:work-stealing) - Umut A. Acar 2016
7677

7778
#### Tutorials
7879

‎benchmark/mnist/tbb.cpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ void run_tbb(MNIST& D, unsigned num_threads) {
108108
}
109109
} // End of all epoch
110110

111-
return;
112-
113111
for(size_t i=0; i<num_par_shf; i++) {
114112
shuffle_tasks[i]->try_put(continue_msg());
115113
}

‎taskflow/core/executor.hpp‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Executor {
7575
struct Worker {
7676
std::mt19937 rdgen { std::random_device{}() };
7777
WorkStealingQueue<Node*> queue;
78+
std::optional<Node*> cache;
7879
};
7980

8081
struct PerThread {
@@ -226,7 +227,7 @@ class Executor {
226227
void _spawn(unsigned);
227228
void _exploit_task(unsigned, std::optional<Node*>&);
228229
void _explore_task(unsigned, std::optional<Node*>&);
229-
void _schedule(Node*);
230+
void _schedule(Node*, bool);
230231
void _schedule(PassiveVector<Node*>&);
231232
void _invoke(unsigned, Node*);
232233
void _invoke_static_work(unsigned, Node*);
@@ -417,11 +418,22 @@ inline void Executor::_exploit_task(unsigned i, std::optional<Node*>& t) {
417418

418419
do {
419420
_invoke(i, *t);
420-
t = worker.queue.pop();
421+
422+
if(worker.cache) {
423+
t = *worker.cache;
424+
worker.cache = std::nullopt;
425+
}
426+
else {
427+
t = worker.queue.pop();
428+
}
429+
421430
} while(t);
422431

423432
--_num_actives;
424433
}
434+
else {
435+
assert(!_workers[i].cache);
436+
}
425437
}
426438

427439
// Function: _wait_for_tasks
@@ -478,7 +490,7 @@ inline void Executor::remove_observer() {
478490
// Procedure: _schedule
479491
// The main procedure to schedule a give task node.
480492
// Each task node has two types of tasks - regular and subflow.
481-
inline void Executor::_schedule(Node* node) {
493+
inline void Executor::_schedule(Node* node, bool bypass) {
482494

483495
// module node need another initialization
484496
if(node->_module != nullptr && !node->is_spawned()) {
@@ -493,7 +505,13 @@ inline void Executor::_schedule(Node* node) {
493505

494506
// caller is a worker to this pool
495507
if(auto& pt = _per_thread(); pt.pool == this) {
496-
_workers[pt.worker_id].queue.push(node);
508+
if(!bypass) {
509+
_workers[pt.worker_id].queue.push(node);
510+
}
511+
else {
512+
assert(!_workers[pt.worker_id].cache);
513+
_workers[pt.worker_id].cache = node;
514+
}
497515
return;
498516
}
499517

@@ -673,12 +691,22 @@ inline void Executor::_invoke(unsigned me, Node* node) {
673691
}
674692

675693
// At this point, the node storage might be destructed.
694+
Node* cache {nullptr};
695+
676696
for(size_t i=0; i<num_successors; ++i) {
677697
if(--(node->_successors[i]->_num_dependents) == 0) {
678-
_schedule(node->_successors[i]);
698+
if(cache) {
699+
//_schedule(node->_successors[i]);
700+
_schedule(cache, false);
701+
}
702+
cache = node->_successors[i];
679703
}
680704
}
681705

706+
if(cache) {
707+
_schedule(cache, true);
708+
}
709+
682710
// A node without any successor should check the termination of topology
683711
if(num_successors == 0) {
684712
if(--(node->_topology->_num_sinks) == 0) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL