28 #include <gts/micro_scheduler/WorkerPool.h>
29 #include <gts/micro_scheduler/MicroScheduler.h>
33 namespace gts_examples {
43 sum = predecessorSum[0] + predecessorSum[1];
45 for(
int iSucc = 0; iSucc < 2; ++iSucc)
47 if (pSuccessors[iSucc])
49 pSuccessors[iSucc]->predecessorSum[iSucc] = sum;
50 if (pSuccessors[iSucc]->removeRef(1) == 1)
61 uint64_t predecessorSum[2] = {0, 0};
66 void weaklyDynamicTaskGraph_wavefront(
int width,
int height)
68 printf (
"================\n");
69 printf (
"weaklyDynamicTaskGraph_wavefront\n");
70 printf (
"================\n");
98 result = microScheduler.
initialize(&workerPool);
101 auto start = std::chrono::high_resolution_clock::now();
106 std::vector<std::vector<GridSumTask*>> taskGrid(width);
108 for (
int ii = width - 1; ii >= 0; --ii)
110 taskGrid[ii].resize(height);
112 for (
int jj = height - 1; jj >= 0; --jj)
117 pTask->
addRef((ii > 0) + (jj > 0), memory_order::relaxed);
121 pTask->pSuccessors[0] = ii + 1 < width ? taskGrid[ii+1][jj] :
nullptr;
122 pTask->pSuccessors[1] = jj + 1 < height ? taskGrid[ii][jj+1] :
nullptr;
124 taskGrid[ii][jj] = pTask;
132 GridSumTask* pRoot = taskGrid[0][0];
133 GridSumTask* pLast = taskGrid[width-1][height-1];
136 pRoot->predecessorSum[0] = 1;
140 pLast->addRef(1, memory_order::relaxed);
144 pLast->spawnAndWaitForAll(pRoot);
149 printf(
"Sum: %" PRIu64
"\n", pLast->sum);
154 auto end = std::chrono::high_resolution_clock::now();
155 std::cout <<
"Time (ms): " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << std::endl;
A work-stealing task scheduler. The scheduler is executed by the WorkerPool it is initialized with.
Definition: MicroScheduler.h:81
void spawnTask(Task *pTask, uint32_t priority=0)
Spawns the specified 'pTask' to be executed by the scheduler. Spawned tasks are executed in LIFO orde...
bool initialize(WorkerPool *pWorkerPool)
Initializes the MicroScheduler and attaches it to pWorkPool, where each worker in pWorkPool will exec...
void destoryTask(Task *pTask)
Manually destroy pTask. Undefined if this Task is executing.
GTS_INLINE TTask * allocateTask(TArgs &&... args)
Allocates a new Task object of type TTask.
Definition: MicroScheduler.h:145
A Task payload that embeds TFunc and TArgs into the Task's data. It makes it easy to construct a Task...
Definition: Task.h:120
GTS_INLINE int32_t addRef(int32_t count=1, gts::memory_order order=gts::memory_order::seq_cst)
Definition: Task.inl:84
A collection of running Worker threads that a MicroScheduler can be run on.
Definition: WorkerPool.h:54
bool initialize(uint32_t threadCount=0)
Definition: 6_weakly_dynamic_task_graph_wavefront.h:38
#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
MicroScheduler * pMicroScheduler
The MicroScheduler executing the Task.
Definition: MicroSchedulerTypes.h:59