annotate src/parallel_execution/TaskManagerImpl.cbc @ 355:45afe5d70956

Fix
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 22 Jun 2017 16:20:56 +0900
parents b07078bd1f2c
children d6ce4273e7d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
1 #include "../context.h"
278
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
2
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
3 #include <stdio.h>
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
4
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
5 void createWorkers(struct Context* context, TaskManager* taskManeger, TaskManagerImpl* taskManagerImpl);
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
6
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
7 TaskManager* createTaskManagerImpl(struct Context* context, int numCPU, int numGPU, int numIO) {
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
8 struct TaskManager* taskManager = new TaskManager();
326
f23f6d0aa4e9 Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 319
diff changeset
9 // 0...numIO-1 IOProcessor
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
10 // numIO...numIO+numGPU-1 GPUProcessor
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
11 // numIO+numGPU...numIO+numGPU+numCPU-1 CPUProcessor
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
12 taskManager->io = 0;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
13 taskManager->gpu = numIO;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
14 taskManager->cpu = numIO+numGPU;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
15 taskManager->maxCPU = numIO+numGPU+numCPU;
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
16 taskManager->spawnTasks = C_spawnTasksTaskManager;
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
17 taskManager->spawn = C_spawnTaskManager;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
18 taskManager->shutdown = C_shutdownTaskManager;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
19 struct TaskManagerImpl* taskManagerImpl = new TaskManagerImpl();
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
20 taskManagerImpl -> activeQueue = createSingleLinkedQueue(context);
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
21 taskManagerImpl -> taskQueue = createSingleLinkedQueue(context);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
22 taskManagerImpl -> numWorker = taskManager->maxCPU;
352
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
23 taskManagerImpl -> loopCounter = new LoopCounter();
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
24 taskManagerImpl -> loopCounter -> i = 0;
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
25 createWorkers(context, taskManager, taskManagerImpl);
316
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 312
diff changeset
26 taskManager->taskManager = (union Data*)taskManagerImpl;
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
27 return taskManager;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
28 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
29
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
30 void createWorkers(struct Context* context, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) {
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
31 int i = 0;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
32 taskManagerImpl->workers = (Worker**)ALLOC_ARRAY(context, Worker, taskManager->maxCPU);
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
33 for (;i<taskManager->gpu;i++) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
34 Queue* queue = createSynchronizedQueue(context);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
35 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
36 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
37 for (;i<taskManager->cpu;i++) {
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
38 #ifdef USE_CUDAWorker
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 288
diff changeset
39 Queue* queue = createSynchronizedQueue(context);
319
a15511b1a6e0 separate cuda.c, and USE_CUDA_MAIN_THREAD flag
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 317
diff changeset
40 #ifndef USE_CUDA_MAIN_THREAD
a15511b1a6e0 separate cuda.c, and USE_CUDA_MAIN_THREAD flag
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 317
diff changeset
41 taskManagerImpl->workers[i] = (Worker*)createCUDAWorker(context, i, queue,0);
a15511b1a6e0 separate cuda.c, and USE_CUDA_MAIN_THREAD flag
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 317
diff changeset
42 #else
316
54d203daf06b CUDAtwice.cbc is called.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 312
diff changeset
43 taskManagerImpl->workers[i] = (Worker*)queue;
319
a15511b1a6e0 separate cuda.c, and USE_CUDA_MAIN_THREAD flag
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 317
diff changeset
44 #endif
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
45 #else
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
46 Queue* queue = createSynchronizedQueue(context);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
47 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
326
f23f6d0aa4e9 Add examples/calc.cbc and build but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 319
diff changeset
48 #endif
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
49 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
50 for (;i<taskManager->maxCPU;i++) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
51 Queue* queue = createSynchronizedQueue(context);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
52 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
53 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
54 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
55
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
56 __code spawnTasksTaskManager(struct TaskManager* taskManager, struct TaskManagerImpl* taskManagerImpl, struct Context** contexts) {
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
57 int i = taskManagerImpl->loopCounter->i;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
58 struct Context* task = contexts[i];
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
59 if(i < GET_SIZE(contexts)) {
355
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 353
diff changeset
60 taskManagerImpl->loopCounter->i++;
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
61 taskManager->context = task;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
62 taskManager->next = C_spawnTasksTaskManager;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
63 goto meta(context, C_setWorker);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
64 }
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
65 taskManagerImpl->loopCounter->i = 0;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
66 goto meta(context, C_spawnTasksTaskManager1);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
67 }
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
68
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
69 __code spawnTasksTaskManager_stub(struct Context* context) {
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
70 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
71 goto spawnTasksTaskManager(context,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
72 Gearef(context, TaskManager),
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
73 taskManager,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
74 Gearef(context, TaskManager)->contexts);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
75 }
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
76
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
77 __code spawnTasksTaskManager1(struct TaskManager* taskManager, struct TaskManagerImpl* taskManagerImpl, struct Context** contexts, __code next(...)) {
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
78 int i = taskManagerImpl->loopCounter->i;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
79 struct Context* task = contexts[i];
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
80 if(i < GET_SIZE(contexts)) {
355
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 353
diff changeset
81 taskManagerImpl->loopCounter->i++;
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
82 taskManager->context = task;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
83 taskManager->next = C_spawnTasksTaskManager1;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
84 goto meta(context, C_spawnTaskManager);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
85 }
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
86 taskManagerImpl->loopCounter->i = 0;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
87 goto meta(context, next);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
88 }
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
89
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
90 __code spawnTasksTaskManager1_stub(struct Context* context) {
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
91 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
92 goto spawnTasksTaskManager1(context,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
93 Gearef(context, TaskManager),
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
94 taskManager,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
95 Gearef(context, TaskManager)->contexts,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
96 Gearef(context, TaskManager)->next1);
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
97 }
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
98
352
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
99 __code setWorker(struct TaskManagerImpl* taskManager, struct Context* task) {
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
100 task->workerId = taskManager->sendWorkerIndex;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
101 if(++taskManager->sendWorkerIndex >= taskManager->numWorker) {
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
102 taskManager->sendWorkerIndex = 0;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
103 }
352
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
104 goto meta(context, C_setWaitTask);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
105 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
106
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
107 __code setWorker_stub(struct Context* context) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
108 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
109 goto setWorker(context, taskManager, Gearef(context, TaskManager)->context);
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
110 }
2c2e4e597eb0 generate no compile errors
mir3636
parents: 279
diff changeset
111
352
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
112 __code setWaitTask(struct Queue* queue, struct Context* task, struct LoopCounter* loopCounter, __code next(...)) {
348
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
113 int i = loopCounter->i;
349
01e0fa598ce3 Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 348
diff changeset
114 if(task->idg + i < task->maxIdg) {
348
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
115 loopCounter->i++;
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
116 queue->queue = (Data *)GET_WAIT_LIST(task->data[task->idg + i]);
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
117 queue->next = C_setWaitTask;
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
118 queue->data = (Data *)task;
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
119 goto meta(context, queue->queue->Queue.put);
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
120 }
352
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
121 loopCounter->i = 0;
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
122 goto next(...);
327
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
123 }
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
124
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
125 __code setWaitTask_stub(struct Context* context) {
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
126 struct Context* task = Gearef(context, TaskManager)->context;
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
127 goto setWaitTask(context, Gearef(context, Queue), task, Gearef(task, LoopCounter), Gearef(context, TaskManager)->next);
327
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
128 }
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
129
352
3e01e963eb2d Fix compile error for calc example but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 349
diff changeset
130 __code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) {
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
131 if (task->idgCount == 0) {
327
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
132 goto meta(context, C_taskSend);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
133 } else {
327
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
134 pthread_mutex_unlock(&taskManager->mutex);
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
135 goto next(...);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
136 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
137 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
138
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
139 __code spawnTaskManager_stub(struct Context* context) {
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
140 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
141 pthread_mutex_lock(&taskManager->mutex);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
142 goto spawnTaskManager(context,
348
c03159481cb6 Par goto exchange inline expansion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 327
diff changeset
143 taskManager,
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
144 Gearef(context, TaskManager)->context,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
145 Gearef(context, TaskManager)->next);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
146 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
147
327
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
148 __code taskSend(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) {
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
149 struct Queue* tasks = taskManager->workers[task->workerId]->tasks;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
150 queue->queue = (union Data*)tasks;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
151 queue->data = (union Data*)task;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
152 queue->next = next;
327
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
153 pthread_mutex_unlock(&taskManager->mutex);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
154 goto meta(context, tasks->put);
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
155 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
156
327
534601ed8c50 Running dependency example for single thread and single task
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 326
diff changeset
157 __code taskSend_stub(struct Context* context) {
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
158 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
353
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
159 goto taskSend(context,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
160 taskManager, Gearef(context, Queue),
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
161 Gearef(context, TaskManager)->context,
b07078bd1f2c Add spawn Tasks to TaskManagerImpl
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 352
diff changeset
162 Gearef(context, TaskManager)->next);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
163 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
164
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
165 __code shutdownTaskManager(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct TaskManagerImpl* taskManagerImpl, struct Queue* queue, __code next(...)) {
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
166 int i = loopCounter->i;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
167 if (taskManager->cpu <= i && i < taskManager->maxCPU) {
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
168 struct Queue* tasks = taskManagerImpl->workers[i]->tasks;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
169 queue->queue = (union Data*)tasks;
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
170 queue->data = NULL;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
171 queue->next = C_shutdownTaskManager1;
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
172 goto meta(context, tasks->put);
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
173 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
174
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
175 loopCounter->i = 0;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
176 goto meta(context, next);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
177 }
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
178
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
179 __code shutdownTaskManager_stub(struct Context* context) {
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
180 TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
181 goto shutdownTaskManager(context, Gearef(context, LoopCounter), &Gearef(context, TaskManager)->taskManager->TaskManager, taskManagerImpl, Gearef(context, Queue), Gearef(context, TaskManager)->next);
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents:
diff changeset
182 }
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
183
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
184 __code shutdownTaskManager1(struct LoopCounter* loopCounter, TaskManagerImpl* taskManagerImpl) {
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
185 int i = loopCounter->i;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
186 pthread_join(taskManagerImpl->workers[i]->worker->CPUWorker.thread, NULL);
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
187 loopCounter->i++;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
188 goto meta(context, C_shutdownTaskManager);
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
189 }
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
190
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
191 __code shutdownTaskManager1_stub(struct Context* context) {
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
192 TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
193 goto shutdownTaskManager1(context, Gearef(context, LoopCounter), taskManagerImpl);
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
194 }