From ca8812f6a5d583717afaff3ac3108e0e0f4066a4 Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Sat, 3 Jun 2023 00:20:44 +0800 Subject: [PATCH 1/4] Add WFShuffleTask. --- src/factory/WFAlgoTaskFactory.h | 49 ++++++++++++++++---- src/factory/WFAlgoTaskFactory.inl | 77 +++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 9 deletions(-) diff --git a/src/factory/WFAlgoTaskFactory.h b/src/factory/WFAlgoTaskFactory.h index 88722c30..af8e0936 100644 --- a/src/factory/WFAlgoTaskFactory.h +++ b/src/factory/WFAlgoTaskFactory.h @@ -59,6 +59,20 @@ struct MergeOutput T *last; }; +template +struct ShuffleInput +{ + T *first; + T *last; +}; + +template +struct ShuffleOutput +{ + T *first; + T *last; +}; + template using ReduceInput = std::vector>; @@ -79,6 +93,12 @@ using WFMergeTask = WFThreadTask, template using merge_callback_t = std::function *)>; +template +using WFShuffleTask = WFThreadTask, + algorithm::ShuffleOutput>; +template +using shuffle_callback_t = std::function *)>; + template using WFReduceTask = WFThreadTask, algorithm::ReduceOutput>; @@ -99,6 +119,17 @@ public: CMP compare, CB callback); + template> + static WFSortTask *create_psort_task(const std::string& queue_name, + T *first, T *last, + CB callback); + + template> + static WFSortTask *create_psort_task(const std::string& queue_name, + T *first, T *last, + CMP compare, + CB callback); + template> static WFMergeTask *create_merge_task(const std::string& queue_name, T *first1, T *last1, @@ -114,16 +145,16 @@ public: CMP compare, CB callback); - template> - static WFSortTask *create_psort_task(const std::string& queue_name, - T *first, T *last, - CB callback); + template> + static WFShuffleTask *create_shuffle_task(const std::string& queue_name, + T *first, T *last, + CB callback); - template> - static WFSortTask *create_psort_task(const std::string& queue_name, - T *first, T *last, - CMP compare, - CB callback); + template> + static WFShuffleTask *create_shuffle_task(const std::string& queue_name, + T *first, T *last, + URBG generator, + CB callback); template, diff --git a/src/factory/WFAlgoTaskFactory.inl b/src/factory/WFAlgoTaskFactory.inl index d0901230..05c4a4a8 100644 --- a/src/factory/WFAlgoTaskFactory.inl +++ b/src/factory/WFAlgoTaskFactory.inl @@ -17,6 +17,8 @@ */ #include +#include +#include #include #include #include @@ -425,6 +427,81 @@ WFSortTask *WFAlgoTaskFactory::create_psort_task(const std::string& name, std::move(callback)); } +/****************** Shuffle ******************/ + +template +class __WFShuffleTask : public WFShuffleTask +{ +protected: + virtual void execute() + { + std::shuffle(this->input.first, this->input.last, + std::mt19937_64(random())); + this->output.first = this->input.first; + this->output.last = this->input.last; + } + +public: + __WFShuffleTask(ExecQueue *queue, Executor *executor, + T *first, T *last, + shuffle_callback_t&& cb) : + WFShuffleTask(queue, executor, std::move(cb)) + { + this->input.first = first; + this->input.last = last; + this->output.first = NULL; + this->output.last = NULL; + } +}; + +template +class __WFShuffleTaskGen : public __WFShuffleTask +{ +protected: + virtual void execute() + { + std::shuffle(this->input.first, this->input.last, + std::move(this->generator)); + this->output.first = this->input.first; + this->output.last = this->input.last; + } + +protected: + URBG generator; + +public: + __WFShuffleTaskGen(ExecQueue *queue, Executor *executor, + T *first, T *last, URBG&& gen, + shuffle_callback_t&& cb) : + __WFShuffleTask(queue, executor, std::move(cb)), + generator(std::move(gen)) + { + } +}; + +template +WFShuffleTask *WFAlgoTaskFactory::create_shuffle_task(const std::string& name, + T *first, T *last, + CB callback) +{ + return new __WFShuffleTask(WFGlobal::get_exec_queue(name), + WFGlobal::get_compute_executor(), + first, last, + std::move(callback)); +} + +template +WFShuffleTask *WFAlgoTaskFactory::create_shuffle_task(const std::string& name, + T *first, T *last, + URBG generator, + CB callback) +{ + return new __WFShuffleTaskGen(WFGlobal::get_exec_queue(name), + WFGlobal::get_compute_executor(), + first, last, std::move(generator), + std::move(callback)); +} + /****************** MapReduce ******************/ template From 6fbcbe7fcf154d049b3e9e3f03ddbc8b55cf117d Mon Sep 17 00:00:00 2001 From: XieHan Date: Sun, 4 Jun 2023 02:35:26 +0800 Subject: [PATCH 2/4] Add WFRmoveTask and WFUniqueTask. --- src/factory/WFAlgoTaskFactory.h | 52 +++++++++++++++++++++ src/factory/WFAlgoTaskFactory.inl | 75 +++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/src/factory/WFAlgoTaskFactory.h b/src/factory/WFAlgoTaskFactory.h index af8e0936..bbeda0af 100644 --- a/src/factory/WFAlgoTaskFactory.h +++ b/src/factory/WFAlgoTaskFactory.h @@ -73,6 +73,35 @@ struct ShuffleOutput T *last; }; +template +struct RemoveInput +{ + T *first; + T *last; + T value; +}; + +template +struct RemoveOutput +{ + T *first; + T *last; +}; + +template +struct UniqueInput +{ + T *first; + T *last; +}; + +template +struct UniqueOutput +{ + T *first; + T *last; +}; + template using ReduceInput = std::vector>; @@ -99,6 +128,18 @@ using WFShuffleTask = WFThreadTask, template using shuffle_callback_t = std::function *)>; +template +using WFRemoveTask = WFThreadTask, + algorithm::RemoveOutput>; +template +using remove_callback_t = std::function *)>; + +template +using WFUniqueTask = WFThreadTask, + algorithm::UniqueOutput>; +template +using unique_callback_t = std::function *)>; + template using WFReduceTask = WFThreadTask, algorithm::ReduceOutput>; @@ -156,6 +197,17 @@ public: URBG generator, CB callback); + template> + static WFRemoveTask *create_remove_task(const std::string& queue_name, + T *first, T *last, + T value, + CB callback); + + template> + static WFUniqueTask *create_unique_task(const std::string& queue_name, + T *first, T *last, + CB callback); + template, class CB = reduce_callback_t> diff --git a/src/factory/WFAlgoTaskFactory.inl b/src/factory/WFAlgoTaskFactory.inl index 05c4a4a8..fec80d47 100644 --- a/src/factory/WFAlgoTaskFactory.inl +++ b/src/factory/WFAlgoTaskFactory.inl @@ -502,6 +502,81 @@ WFShuffleTask *WFAlgoTaskFactory::create_shuffle_task(const std::string& name std::move(callback)); } +/****************** Remove ******************/ + +template +class __WFRemoveTask : public WFRemoveTask +{ +protected: + virtual void execute() + { + this->output.last = std::remove(this->input.first, this->input.last, + this->input.value); + this->output.first = this->input.first; + } + +public: + __WFRemoveTask(ExecQueue *queue, Executor *executor, + T *first, T *last, T&& value, + remove_callback_t&& cb) : + WFRemoveTask(queue, executor, std::move(cb)) + { + this->input.first = first; + this->input.last = last; + this->input.value = std::move(value); + this->output.first = NULL; + this->output.last = NULL; + } +}; + +template +WFRemoveTask *WFAlgoTaskFactory::create_remove_task(const std::string& name, + T *first, T *last, + T value, + CB callback) +{ + return new __WFRemoveTask(WFGlobal::get_exec_queue(name), + WFGlobal::get_compute_executor(), + first, last, std::move(value), + std::move(callback)); +} + +/****************** Unique ******************/ + +template +class __WFUniqueTask : public WFUniqueTask +{ +protected: + virtual void execute() + { + this->output.last = std::unique(this->input.first, this->input.last); + this->output.first = this->input.first; + } + +public: + __WFUniqueTask(ExecQueue *queue, Executor *executor, + T *first, T *last, + unique_callback_t&& cb) : + WFUniqueTask(queue, executor, std::move(cb)) + { + this->input.first = first; + this->input.last = last; + this->output.first = NULL; + this->output.last = NULL; + } +}; + +template +WFUniqueTask *WFAlgoTaskFactory::create_unique_task(const std::string& name, + T *first, T *last, + CB callback) +{ + return new __WFUniqueTask(WFGlobal::get_exec_queue(name), + WFGlobal::get_compute_executor(), + first, last, + std::move(callback)); +} + /****************** MapReduce ******************/ template From 036e00feb94a4c9dcb805cbd07d6245a79219aa0 Mon Sep 17 00:00:00 2001 From: XieHan Date: Sun, 4 Jun 2023 02:35:42 +0800 Subject: [PATCH 3/4] Remove include WFAlgoTaskFactory.h from WFTaskFactory.h. --- src/factory/WFTaskFactory.h | 1 - tutorial/tutorial-07-sort_task.cc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/factory/WFTaskFactory.h b/src/factory/WFTaskFactory.h index c3047453..df2a45d4 100644 --- a/src/factory/WFTaskFactory.h +++ b/src/factory/WFTaskFactory.h @@ -34,7 +34,6 @@ #include "WFTask.h" #include "WFGraphTask.h" #include "EndpointParams.h" -#include "WFAlgoTaskFactory.h" // Network Client/Server tasks diff --git a/tutorial/tutorial-07-sort_task.cc b/tutorial/tutorial-07-sort_task.cc index ee965ad5..f471e1bc 100644 --- a/tutorial/tutorial-07-sort_task.cc +++ b/tutorial/tutorial-07-sort_task.cc @@ -18,7 +18,7 @@ #include #include -#include "workflow/WFTaskFactory.h" +#include "workflow/WFAlgoTaskFactory.h" #include "workflow/WFFacilities.h" using namespace algorithm; From 47e2910eef8740faba8ff7dc221d1a0ad831e281 Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Mon, 5 Jun 2023 22:54:01 +0800 Subject: [PATCH 4/4] Add WFReverseTask, WFRotateTask. --- src/factory/WFAlgoTaskFactory.h | 51 +++++++++++++++++++++ src/factory/WFAlgoTaskFactory.inl | 75 +++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/src/factory/WFAlgoTaskFactory.h b/src/factory/WFAlgoTaskFactory.h index bbeda0af..e85c0d3c 100644 --- a/src/factory/WFAlgoTaskFactory.h +++ b/src/factory/WFAlgoTaskFactory.h @@ -102,6 +102,35 @@ struct UniqueOutput T *last; }; +template +struct ReverseInput +{ + T *first; + T *last; +}; + +template +struct ReverseOutput +{ + T *first; + T *last; +}; + +template +struct RotateInput +{ + T *first; + T *middle; + T *last; +}; + +template +struct RotateOutput +{ + T *first; + T *last; +}; + template using ReduceInput = std::vector>; @@ -140,6 +169,18 @@ using WFUniqueTask = WFThreadTask, template using unique_callback_t = std::function *)>; +template +using WFReverseTask = WFThreadTask, + algorithm::ReverseOutput>; +template +using reverse_callback_t = std::function *)>; + +template +using WFRotateTask = WFThreadTask, + algorithm::RotateOutput>; +template +using rotate_callback_t = std::function *)>; + template using WFReduceTask = WFThreadTask, algorithm::ReduceOutput>; @@ -208,6 +249,16 @@ public: T *first, T *last, CB callback); + template> + static WFReverseTask *create_reverse_task(const std::string& queue_name, + T *first, T *last, + CB callback); + + template> + static WFRotateTask *create_rotate_task(const std::string& queue_name, + T *first, T *middle, T *last, + CB callback); + template, class CB = reduce_callback_t> diff --git a/src/factory/WFAlgoTaskFactory.inl b/src/factory/WFAlgoTaskFactory.inl index fec80d47..8184777a 100644 --- a/src/factory/WFAlgoTaskFactory.inl +++ b/src/factory/WFAlgoTaskFactory.inl @@ -577,6 +577,81 @@ WFUniqueTask *WFAlgoTaskFactory::create_unique_task(const std::string& name, std::move(callback)); } +/****************** Reverse ******************/ + +template +class __WFReverseTask : public WFReverseTask +{ +protected: + virtual void execute() + { + std::reverse(this->input.first, this->input.last); + this->output.first = this->input.first; + this->output.last = this->input.last; + } + +public: + __WFReverseTask(ExecQueue *queue, Executor *executor, + T *first, T *last, + reverse_callback_t&& cb) : + WFReverseTask(queue, executor, std::move(cb)) + { + this->input.first = first; + this->input.last = last; + this->output.first = NULL; + this->output.last = NULL; + } +}; + +template +WFReverseTask *WFAlgoTaskFactory::create_reverse_task(const std::string& name, + T *first, T *last, + CB callback) +{ + return new __WFReverseTask(WFGlobal::get_exec_queue(name), + WFGlobal::get_compute_executor(), + first, last, + std::move(callback)); +} + +/****************** Rotate ******************/ + +template +class __WFRotateTask : public WFRotateTask +{ +protected: + virtual void execute() + { + std::rotate(this->input.first, this->input.middle, this->input.last); + this->output.first = this->input.first; + this->output.last = this->input.last; + } + +public: + __WFRotateTask(ExecQueue *queue, Executor *executor, + T *first, T* middle, T *last, + rotate_callback_t&& cb) : + WFRotateTask(queue, executor, std::move(cb)) + { + this->input.first = first; + this->input.middle = middle; + this->input.last = last; + this->output.first = NULL; + this->output.last = NULL; + } +}; + +template +WFRotateTask *WFAlgoTaskFactory::create_rotate_task(const std::string& name, + T *first, T *middle, T *last, + CB callback) +{ + return new __WFRotateTask(WFGlobal::get_exec_queue(name), + WFGlobal::get_compute_executor(), + first, middle, last, + std::move(callback)); +} + /****************** MapReduce ******************/ template