26 #include "gts/micro_scheduler/WorkerPool.h"
27 #include "gts/micro_scheduler/MicroScheduler.h"
28 #include "gts/micro_scheduler/patterns/ParallelFor.h"
29 #include "gts/micro_scheduler/patterns/Partitioners.h"
30 #include "gts/micro_scheduler/patterns/Range1d.h"
34 namespace gts_examples {
37 void simplestIndexedParallelFor()
39 printf (
"================\n");
40 printf (
"simplestIndexedParallelFor\n");
41 printf (
"================\n");
51 result = microScheduler.
initialize(&workerPool);
54 size_t const elementCount = 1 << 16;
61 std::vector<int> vec(elementCount, 0);
62 parFor(
size_t(0),
size_t(vec.size()), [&vec](
size_t idx) { vec[idx]++; });
65 for (
auto const& v : vec)
72 void simplerIteratorParallelFor()
74 printf (
"================\n");
75 printf (
"simplerIteratorParallelFor\n");
76 printf (
"================\n");
86 result = microScheduler.
initialize(&workerPool);
89 size_t const elementCount = 1 << 16;
100 size_t const blockSize = 1;
103 std::vector<int> vec(elementCount, 0);
107 [](std::vector<int>::iterator iter) { (*iter)++; });
110 for (
auto const& v : vec)
117 void fullParallelFor()
119 printf (
"================\n");
120 printf (
"fullParallelFor\n");
121 printf (
"================\n");
131 result = microScheduler.
initialize(&workerPool);
134 size_t const elementCount = 1 << 16;
135 std::vector<int> vec(elementCount, 0);
139 size_t const blockSize = 1;
150 std::vector<int>& vec = *(std::vector<int>*)pData;
153 for (
size_t idx = range.begin(); idx != range.end(); ++idx)
167 for (
auto const& v : vec)
Adaptively subdivides a TRange based on demand from the scheduler.
Definition: AdaptivePartitioner.h:28
A work-stealing task scheduler. The scheduler is executed by the WorkerPool it is initialized with.
Definition: MicroScheduler.h:81
bool initialize(WorkerPool *pWorkerPool)
Initializes the MicroScheduler and attaches it to pWorkPool, where each worker in pWorkPool will exec...
A construct that maps parallel-for behavior to a MicroScheduler.
Definition: ParallelFor.h:48
An iteration range over a 1D data set. Splits divide the range in two based unless the minimum size i...
Definition: Range1d.h:56
A collection of running Worker threads that a MicroScheduler can be run on.
Definition: WorkerPool.h:54
bool initialize(uint32_t threadCount=0)
#define GTS_ASSERT(expr)
Causes execution to break when expr is false.
Definition: Assert.h:144
The context associated with the task being executed.
Definition: MicroSchedulerTypes.h:54