27 #include "gts/micro_scheduler/WorkerPool.h"
28 #include "gts/micro_scheduler/MicroScheduler.h"
29 #include "gts/micro_scheduler/patterns/ParallelFor.h"
31 #include "gts/macro_scheduler/Node.h"
32 #include "gts/macro_scheduler/compute_resources/MicroScheduler_Workload.h"
33 #include "gts/macro_scheduler/compute_resources/MicroScheduler_ComputeResource.h"
34 #include "gts/macro_scheduler/schedulers/homogeneous/central_queue/CentralQueue_MacroScheduler.h"
38 namespace gts_examples {
41 void basicParallelFor()
43 printf (
"================\n");
44 printf (
"basicParallelFor\n");
45 printf (
"================\n");
54 result = microScheduler.
initialize(&workerPool);
61 std::vector<int> vec(1000000, 0);
62 parFor(vec.begin(), vec.end(), [](std::vector<int>::iterator iter) { (*iter)++; });
65 for (
auto const& v : vec)
75 printf(
"SUCCESS!\n\n");
79 void basicMacroSchedulerNodeGraph()
81 printf (
"================\n");
82 printf (
"basicMacroSchedulerNodeGraph\n");
83 printf (
"================\n");
109 generalizedDagSchedulerDesc.
computeResources.push_back(µSchedulerCompResource);
112 pMacroScheduler->
init(generalizedDagSchedulerDesc);
145 pB->addSuccessor(pD);
146 pC->addSuccessor(pD);
154 for(
size_t iLoop = 0; iLoop < 10; ++iLoop)
156 printf(
"--- Frame ---\n");
157 pMacroScheduler->
executeSchedule(pSchedule, microSchedulerCompResource.id());
160 printf(
"SUCCESS!\n\n");
164 void basicMacroSchedulerNodeGraphWithParallelFor()
166 printf (
"================\n");
167 printf (
"basicMacroSchedulerNodeGraphWithParallelFor\n");
168 printf (
"================\n");
185 generalizedDagSchedulerDesc.
computeResources.push_back(µSchedulerCompResource);
188 pMacroScheduler->
init(generalizedDagSchedulerDesc);
214 std::vector<int> vec(1000000, 0);
219 parFor(vec.begin(), vec.end(), [](std::vector<int>::iterator iter) { (*iter)++; });
226 parFor(vec.begin(), vec.begin() + vec.size() / 2, [](std::vector<int>::iterator iter) { (*iter) += 2; });
233 parFor(vec.begin() + vec.size() / 2, vec.end(), [](std::vector<int>::iterator iter) { (*iter) += 3; });
240 parFor(vec.begin(), vec.end(), [](std::vector<int>::iterator iter) { (*iter)++; });
247 pB->addSuccessor(pD);
248 pC->addSuccessor(pD);
252 pMacroScheduler->
executeSchedule(pSchedule, microSchedulerCompResource.id());
255 for (
auto iter = vec.begin(); iter != vec.begin() + vec.size() / 2; ++iter)
259 for (
auto iter = vec.begin() + vec.size() / 2; iter != vec.end(); ++iter)
265 printf(
"SUCCESS!\n\n");
A generalized DAG scheduler utilizing work stealing. This scheduler delegates its responsibilities to...
Definition: CentralQueue_MacroScheduler.h:58
A MacroScheduler builds ISchedules for a set of ComputeResources from a DAG of Node.
Definition: MacroScheduler.h:50
virtual Schedule * buildSchedule(Node *pStart, Node *pEnd)=0
virtual void executeSchedule(Schedule *pSchedule, ComputeResourceId id)=0
virtual bool init(MacroSchedulerDesc const &desc)=0
A ComputeResource that wraps a MicroScheduler.
Definition: MicroScheduler_ComputeResource.h:53
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...
void shutdown()
Stops the MicroScheduler and destroys all resources. The TaskSchuduler is now in an unusable state....
A concrete lambda Workload that maps to the MicroScheduler.
Definition: MicroScheduler_Workload.h:116
A Node represents a task in a generalized task DAG. It contains Workloads that are scheduled onto a C...
Definition: Node.h:50
GTS_INLINE TWorkload * addWorkload(TArgs &&... args)
Allocates a new Workload object of type TWorkload.
Definition: Node.h:174
void addSuccessor(Node *pNode)
Add the sucessor Node 'pNode'.
A construct that maps parallel-for behavior to a MicroScheduler.
Definition: ParallelFor.h:48
The execution schedule for all ComputeResources.
Definition: Schedule.h:45
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 description of a MacroSchedulerDesc to create.
Definition: MacroSchedulerTypes.h:60
gts::Vector< ComputeResource * > computeResources
The ComputeResource that the MacroScheduler can schedule to.
Definition: MacroSchedulerTypes.h:62
The context associated with the task being executed.
Definition: MacroSchedulerTypes.h:72