3 #include <SharedSubTask.h>
4 #include <SharedTaskSequencer.h>
5 #include <surfaceinspector/maths/Scalar.hpp>
11 namespace helios{
namespace hpc {
85 template <
typename RandomAccessIterator,
typename Comparator>
132 std::shared_ptr<SharedTaskSequencer>
ch,
137 RandomAccessIterator
begin,
138 RandomAccessIterator
end,
163 size_t const numElements = std::distance(
begin,
end);
170 int const initDepth = (int) std::ceil(std::log2(
tIdx+1));
171 RandomAccessIterator workA =
begin;
172 std::vector<RandomAccessIterator> workB(1,
end);
174 RandomAccessIterator, Comparator
175 >>> childrenTasks(0);
178 for(
int depth = 0 ; depth <
maxDepth ; ++depth){
180 size_t const k = 1 + depth - initDepth;
181 size_t const rightIdx = \
185 RandomAccessIterator workSplit = workA +
186 std::distance(workA, workB[depth]) / 2;
187 std::shared_ptr<SM_ParallelMergeSortSubTask> childTask = \
189 RandomAccessIterator, Comparator
200 childrenTasks.push_back(childTask);
202 workB.push_back(workSplit);
210 std::sort(workA, workB[workB.size()-1],
comparator);
213 for(
int i = childrenTasks.size()-1 ; i >= 0 ; --i){
214 std::shared_ptr<SM_ParallelMergeSortSubTask> childTask = \
216 childTask->getThread()->join();
217 std::inplace_merge(workA, workB[i+1], workB[i],
comparator);
A shared task is said to be a collection of shared sub-tasks. Each shared sub-task can be computed in...
Definition: SharedSubTask.h:16
std::shared_ptr< SharedSubTaskCompletionHandler > ch
The shared sub-task completion handler that handles what must be done after a shared sub-task executi...
Definition: SharedSubTask.h:28
Class providing common operations to work with scalars.
Definition: Scalar.hpp:18
Shared sub-task to sort a sequence using a parallel mergesort like algorithm for shared memory contex...
Definition: SM_ParallelMergeSortSubTask.h:86
size_t numThreads
Definition: SM_ParallelMergeSortSubTask.h:102
SM_ParallelMergeSortSubTask(std::shared_ptr< SharedTaskSequencer > ch, size_t const tIdx, size_t const numThreads, size_t const minElements, int const maxDepth, RandomAccessIterator begin, RandomAccessIterator end, Comparator comparator)
Main constructor for shared context parallel merge sort sub-task.
Definition: SM_ParallelMergeSortSubTask.h:131
RandomAccessIterator end
Definition: SM_ParallelMergeSortSubTask.h:118
std::shared_ptr< SharedTaskSequencer > stSequencer
Definition: SM_ParallelMergeSortSubTask.h:94
int maxDepth
Definition: SM_ParallelMergeSortSubTask.h:110
RandomAccessIterator begin
Definition: SM_ParallelMergeSortSubTask.h:114
size_t tIdx
Thread index in .
Definition: SM_ParallelMergeSortSubTask.h:98
size_t minElements
Definition: SM_ParallelMergeSortSubTask.h:106
void run() override
Implementation of the sort method itself.
Definition: SM_ParallelMergeSortSubTask.h:161
Comparator comparator
Definition: SM_ParallelMergeSortSubTask.h:122