comparison src/parallel_execution/TaskManagerImpl.cbc @ 280:2c2e4e597eb0

generate no compile errors
author mir3636
date Fri, 03 Feb 2017 17:47:27 +0900
parents b5e8fce400a5
children a3448b0f0a56
comparison
equal deleted inserted replaced
279:b5e8fce400a5 280:2c2e4e597eb0
2 2
3 #include <stdio.h> 3 #include <stdio.h>
4 4
5 void createWorkers(struct Context* context, TaskManager* taskManeger, TaskManagerImpl* taskManagerImpl); 5 void createWorkers(struct Context* context, TaskManager* taskManeger, TaskManagerImpl* taskManagerImpl);
6 6
7 TaskManager* createTaskManager(struct Context* context, int numCPU, int numGPU, int numIO) { 7 TaskManager* createTaskManagerImpl(struct Context* context, int numCPU, int numGPU, int numIO) {
8 struct TaskManager* taskManager = new TaskManager(); 8 struct TaskManager* taskManager = new TaskManager();
9 // 0...numIO-1 IOProcessor 9 // 0...numIO-1 IOProcessor
10 // numIO...numIO+numGPU-1 GPUProcessor 10 // numIO...numIO+numGPU-1 GPUProcessor
11 // numIO+numGPU...numIO+numGPU+numCPU-1 CPUProcessor 11 // numIO+numGPU...numIO+numGPU+numCPU-1 CPUProcessor
12 taskManager->io = 0; 12 taskManager->io = 0;
16 taskManager->createTask = C_createTask; 16 taskManager->createTask = C_createTask;
17 taskManager->spawn = C_spawnTaskManager; 17 taskManager->spawn = C_spawnTaskManager;
18 taskManager->shutdown = C_shutdownTaskManager; 18 taskManager->shutdown = C_shutdownTaskManager;
19 struct TaskManagerImpl* taskManagerImpl = new TaskManagerImpl(); 19 struct TaskManagerImpl* taskManagerImpl = new TaskManagerImpl();
20 taskManager->taskManager = (union Data*)taskManagerImpl; 20 taskManager->taskManager = (union Data*)taskManagerImpl;
21 taskManagerImpl -> activeQueue = &createSingleLinkedQueue(context)->Queue; 21 taskManagerImpl -> activeQueue = createSingleLinkedQueue(context);
22 taskManagerImpl -> taskQueue = &createSingleLinkedQueue(context)->Queue; 22 taskManagerImpl -> taskQueue = createSingleLinkedQueue(context);
23 taskManagerImpl -> numWorker = taskManager->maxCPU; 23 taskManagerImpl -> numWorker = taskManager->maxCPU;
24 createWorkers(context, taskManager, taskManagerImpl); 24 createWorkers(context, taskManager, taskManagerImpl);
25 return taskManager; 25 return taskManager;
26 } 26 }
27 27
28 void createWorkers(struct Context* context, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) { 28 void createWorkers(struct Context* context, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) {
29 int i = 0; 29 int i = 0;
30 taskManagerImpl->workers = (Worker**)ALLOC_ARRAY(context, Worker, taskManager->maxCPU); 30 taskManagerImpl->workers = (Worker**)ALLOC_ARRAY(context, Worker, taskManager->maxCPU);
31 for (;i<taskManager->gpu;i++) { 31 for (;i<taskManager->gpu;i++) {
32 Queue* queue = &createSynchronizedQueue(context)->Queue; 32 Queue* queue = createSynchronizedQueue(context);
33 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); 33 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
34 } 34 }
35 for (;i<taskManager->cpu;i++) { 35 for (;i<taskManager->cpu;i++) {
36 #ifdef USE_CUDA 36 #ifdef USE_CUDA
37 #else 37 #else
38 Queue* queue = &createSynchronizedQueue(context)->Queue; 38 Queue* queue = createSynchronizedQueue(context);
39 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); 39 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
40 #endif 40 #endif
41 } 41 }
42 for (;i<taskManager->maxCPU;i++) { 42 for (;i<taskManager->maxCPU;i++) {
43 Queue* queue = &createSynchronizedQueue(context)->Queue; 43 Queue* queue = createSynchronizedQueue(context);
44 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); 44 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
45 } 45 }
46 } 46 }
47 47
48 __code createTask(struct TaskManager* taskManager) { 48 __code createTask(struct TaskManager* taskManager) {
49 taskManager->context = NEW(struct Context); 49 taskManager->context = NEW(struct Context);
50 initContext(taskManager->context); 50 initContext(taskManager->context);
51 goto C_setWorker(...); 51 goto meta(context, C_setWorker);
52 } 52 }
53 53
54 __code setWorker(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { 54 __code setWorker(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) {
55 task->workerId = taskManager->sendWorkerIndex; 55 task->workerId = taskManager->sendWorkerIndex;
56 if(++taskManager->sendWorkerIndex >= taskManager->numWorker) { 56 if(++taskManager->sendWorkerIndex >= taskManager->numWorker) {
57 taskManager->sendWorkerIndex = 0; 57 taskManager->sendWorkerIndex = 0;
58 } 58 }
59 goto next(...); 59 goto next(...);
60 }
61
62 __code setWorker_stub(struct Context* context) {
63 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
64 goto setWorker(context, taskManager, Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next);
60 } 65 }
61 66
62 __code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) { 67 __code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) {
63 if (task->idgCount == 0) { 68 if (task->idgCount == 0) {
64 // enqueue activeQueue 69 // enqueue activeQueue
83 } 88 }
84 89
85 90
86 __code spawnTaskManager1(struct TaskManagerImpl* taskManager) { 91 __code spawnTaskManager1(struct TaskManagerImpl* taskManager) {
87 pthread_mutex_unlock(&taskManager->mutex); 92 pthread_mutex_unlock(&taskManager->mutex);
88 goto C_taskSend(...); 93 goto meta(context, C_taskSend);
89 } 94 }
90 95
91 __code spawnTaskManager1_stub(struct Context* context) { 96 __code spawnTaskManager1_stub(struct Context* context) {
92 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); 97 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
93 goto spawnTaskManager1(context, 98 goto spawnTaskManager1(context,
122 queue->data = NULL; 127 queue->data = NULL;
123 queue->next = next; 128 queue->next = next;
124 goto meta(context, tasks->put); 129 goto meta(context, tasks->put);
125 pthread_join(taskManagerImpl->workers[i]->worker->CPUWorker.thread, NULL); 130 pthread_join(taskManagerImpl->workers[i]->worker->CPUWorker.thread, NULL);
126 loopCounter->i++; 131 loopCounter->i++;
127 goto C_shutdownTaskManager(...); 132 goto meta(context, C_shutdownTaskManager);
128 } 133 }
129 134
130 loopCounter->i = 0; 135 loopCounter->i = 0;
131 goto meta(context, taskManager->next); 136 goto meta(context, taskManager->next);
132 } 137 }