Commit f3fe5ac3 by FritzFlorian

Fix: use new id type in all tasks.

parent 2eb9674a
......@@ -5,6 +5,7 @@
#include <atomic>
#include <pls/pls.h>
#include <pls/internal/base/prohibit_new.h>
using namespace pls;
......@@ -42,10 +43,8 @@ protected:
int left_result;
int right_result;
fib left_child{num_ - 1, &left_result};
spawn_child(left_child);
fib right_child{num_ - 2, &right_result};
spawn_child(right_child);
spawn_child(fib{num_ - 1, &left_result});
spawn_child(fib{num_ - 2, &right_result});
wait_for_all();
*result_ = left_result + right_result;
......@@ -58,14 +57,14 @@ public:
int main() {
scheduler my_scheduler{&my_scheduler_memory, 1};
scheduler my_scheduler{&my_scheduler_memory, 4};
auto start = std::chrono::high_resolution_clock::now();
my_scheduler.perform_work([] (){
int result;
fib fib_sub_task{45, &result};
tbb_task tbb_task{&fib_sub_task};
tbb_task tbb_task{&fib_sub_task, task_id{1}};
scheduler::execute_task(tbb_task);
std::cout << "Result: " << result << std::endl;
......
......@@ -10,23 +10,25 @@ namespace pls {
namespace internal {
namespace scheduling {
class abstract_task {
public:
struct id {
uint32_t id_;
bool auto_generated_;
explicit id(uint32_t id, bool auto_generated=true): id_{id}, auto_generated_{auto_generated} {};
explicit id(uint32_t id, bool auto_generated=false): id_{id}, auto_generated_{auto_generated} {};
bool operator==(const abstract_task::id& other) const {
return id_ == other.id_ && auto_generated_ == other.auto_generated_;
}
};
private:
int depth_;
abstract_task::id unique_id_;
abstract_task* child_task_;
public:
abstract_task(int depth, abstract_task::id unique_id):
abstract_task(const int depth, const abstract_task::id& unique_id):
depth_{depth},
unique_id_{unique_id},
child_task_{nullptr} {}
......@@ -37,6 +39,7 @@ namespace pls {
void set_depth(int depth) { depth_ = depth; }
int depth() const { return depth_; }
id unique_id() const { return unique_id_; }
protected:
virtual bool internal_stealing(abstract_task* other_task) = 0;
virtual bool split_task(base::spin_lock* lock) = 0;
......
......@@ -19,7 +19,7 @@ namespace pls {
base::spin_lock finished_lock_;
public:
explicit root_task(Function function):
abstract_task{0, 0},
abstract_task{0, id{0, true}},
function_{function},
finished_{false} {}
......@@ -51,7 +51,7 @@ namespace pls {
public:
explicit root_worker_task(root_task<Function>* master_task):
abstract_task{0, 0},
abstract_task{0, id{0, true}},
master_task_{master_task} {}
void execute() override {
......
......@@ -37,7 +37,7 @@ namespace pls {
}
public:
run_on_n_threads_task(Function function, int num_threads):
abstract_task{PLS_UNIQUE_ID, 0},
abstract_task{0, id{PLS_UNIQUE_ID, true}},
function_{function},
counter{num_threads - 1} {}
......@@ -66,7 +66,7 @@ namespace pls {
run_on_n_threads_task<Function>* root_;
public:
run_on_n_threads_task_worker(Function function, run_on_n_threads_task<Function>* root):
abstract_task{PLS_UNIQUE_ID, 0},
abstract_task{0, id{PLS_UNIQUE_ID, true}},
function_{function},
root_{root} {}
......
......@@ -70,9 +70,10 @@ namespace pls {
bool split_task(base::spin_lock* /*lock*/) override;
public:
explicit tbb_task(tbb_sub_task* root_task):
abstract_task{0, 0},
explicit tbb_task(tbb_sub_task* root_task, const abstract_task::id& id):
abstract_task{0, id},
root_task_{root_task},
my_stack_{nullptr},
deque_{},
last_stolen_{nullptr} {};
......
#ifndef PLS_LIBRARY_H
#define PLS_LIBRARY_H
#include <pls/internal/scheduling/scheduler.h>
#include <pls/internal/scheduling/tbb_task.h>
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/tbb_task.h"
#include "pls/internal/scheduling/abstract_task.h"
namespace pls {
using internal::scheduling::scheduler;
using internal::scheduling::static_scheduler_memory;
using task_id = internal::scheduling::abstract_task::id;
using internal::scheduling::tbb_sub_task;
using internal::scheduling::tbb_task;
......
......@@ -82,7 +82,7 @@ namespace pls {
if (stolen_sub_task == nullptr) {
return false;
}
tbb_task task{stolen_sub_task};
tbb_task task{stolen_sub_task, this->unique_id()};
// In success case, unlock.
// TODO: this locking is complicated and error prone.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment