Mercurial > hg > GearsTemplate
annotate src/parallel_execution/CPUWorker.cbc @ 372:d6ce4273e7d1
Add dimension task spawn
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 11 Jul 2017 17:47:11 +0900 |
parents | 534601ed8c50 |
children | fb50cf8aa615 |
rev | line source |
---|---|
278 | 1 #include "../context.h" |
272 | 2 |
3 static void start_worker(Worker* worker); | |
4 | |
280 | 5 Worker* createCPUWorker(struct Context* context, int id, Queue* queue) { |
272 | 6 struct Worker* worker = new Worker(); |
7 struct CPUWorker* cpuWorker = new CPUWorker(); | |
8 worker->worker = (union Data*)cpuWorker; | |
9 worker->tasks = queue; | |
10 cpuWorker->id = id; | |
11 worker->taskReceive = C_taskReceiveWorker; | |
12 worker->shutdown = C_shutdownWorker; | |
13 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); | |
14 return worker; | |
15 } | |
16 | |
17 static void start_worker(Worker* worker) { | |
18 CPUWorker* cpuWorker = (CPUWorker*)worker->worker; | |
19 cpuWorker->context = NEW(struct Context); | |
20 initContext(cpuWorker->context); | |
21 Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; | |
282
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
22 goto meta(cpuWorker->context, worker->taskReceive); |
272 | 23 } |
24 | |
25 __code taskReceiveWorker(struct Worker* worker,struct Queue* queue) { | |
26 queue->queue = (union Data*)worker->tasks; | |
27 queue->next = C_getTask; | |
28 goto meta(context, worker->tasks->take); | |
29 } | |
30 | |
31 __code taskReceiveWorker_stub(struct Context* context) { | |
32 goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); | |
33 } | |
34 | |
35 __code getTask(struct Worker* worker, struct Context* task) { | |
36 if (!task) | |
37 return; // end thread | |
38 task->worker = worker; | |
289 | 39 enum Code taskCg = task->next; |
288 | 40 task->next = C_odgCommit; // set CG after task exec |
289 | 41 goto meta(task, taskCg); |
272 | 42 } |
43 | |
44 __code getTask_stub(struct Context* context) { | |
45 Worker* worker = &Gearef(context,Worker)->worker->Worker; | |
46 struct Context* task = &Gearef(context, Queue)->data->Context; | |
47 goto getTask(context, worker, task); | |
48 } | |
49 | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
50 __code odgCommit(struct LoopCounter* loopCounter, struct Context* task) { |
288 | 51 int i = loopCounter->i ; |
52 if(task->odg + i < task->maxOdg) { | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
53 goto meta(task, C_odgCommit1); |
288 | 54 } |
55 loopCounter->i = 0; | |
56 goto meta(context, C_taskReceiveWorker); | |
57 } | |
58 | |
59 __code odgCommit_stub(struct Context* context) { | |
60 struct Context* workerContext = context->worker->worker->CPUWorker.context; | |
61 goto odgCommit(workerContext, | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
62 Gearef(context, LoopCounter), |
288 | 63 context); |
64 } | |
65 | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
66 __code odgCommit1(struct LoopCounter* loopCounter, struct Queue* queue) { |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
67 int i = loopCounter->i ; |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
68 queue->queue = (union Data*)GET_WAIT_LIST(context->data[context->odg+i]); |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
69 queue->whenEmpty = C_odgCommit4; |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
70 queue->next = C_odgCommit2; |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
71 goto meta(context, queue->queue->Queue.isEmpty); |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
72 } |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
73 |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
74 __code odgCommit1_stub(struct Context* context) { |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
75 goto odgCommit1(context, |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
76 Gearef(context, LoopCounter), |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
77 Gearef(context, Queue)); |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
78 } |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
79 |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
80 __code odgCommit2(struct Queue* queue) { |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
81 queue->next = C_odgCommit3; |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
82 goto meta(context, queue->queue->Queue.take); |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
83 } |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
84 |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
85 __code odgCommit2_stub(struct Context* context) { |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
86 goto odgCommit2(context, |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
87 Gearef(context, Queue)); |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
88 } |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
89 |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
90 __code odgCommit3(struct TaskManager* taskManager, struct Context* task) { |
372
d6ce4273e7d1
Add dimension task spawn
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
327
diff
changeset
|
91 int idgCount = task->idgCount; |
d6ce4273e7d1
Add dimension task spawn
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
327
diff
changeset
|
92 if(__sync_bool_compare_and_swap(&task->idgCount, idgCount, idgCount-1)) { // atomic decrement idg counter |
d6ce4273e7d1
Add dimension task spawn
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
327
diff
changeset
|
93 if(idgCount-1 == 0) { |
288 | 94 taskManager->taskManager = (union Data*)task->taskManager; |
95 taskManager->context = task; | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
96 taskManager->next = C_odgCommit1; |
288 | 97 goto meta(context, task->taskManager->spawn); |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
98 } else { |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
99 goto meta(context, C_odgCommit1); |
288 | 100 } |
101 } else { | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
102 goto meta(context, C_odgCommit3); |
288 | 103 } |
104 } | |
105 | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
106 __code odgCommit3_stub(struct Context* context) { |
288 | 107 struct Context* task = &Gearef(context, Queue)->data->Context; |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
108 goto odgCommit3(context, |
288 | 109 Gearef(context, TaskManager), |
110 task); | |
327
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
111 } |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
112 |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
113 __code odgCommit4(struct LoopCounter* loopCounter) { |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
114 loopCounter->i++; |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
115 goto meta(context, C_odgCommit); |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
116 } |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
117 |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
118 __code odgCommit4_stub(struct Context* context) { |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
119 goto odgCommit4(context, |
534601ed8c50
Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
325
diff
changeset
|
120 Gearef(context, LoopCounter)); |
288 | 121 } |
122 | |
272 | 123 __code shutdownWorker(struct CPUWorker* worker) { |
124 } |