comparison src/parallel_execution/TaskManagerImpl.cbc @ 317:51aa65676e37

CUDAtwice.cbc is called now
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 15 Feb 2017 16:28:25 +0900
parents 54d203daf06b
children a15511b1a6e0
comparison
equal deleted inserted replaced
316:54d203daf06b 317:51aa65676e37
20 taskManagerImpl -> activeQueue = createSingleLinkedQueue(context); 20 taskManagerImpl -> activeQueue = createSingleLinkedQueue(context);
21 taskManagerImpl -> taskQueue = createSingleLinkedQueue(context); 21 taskManagerImpl -> taskQueue = createSingleLinkedQueue(context);
22 taskManagerImpl -> numWorker = taskManager->maxCPU; 22 taskManagerImpl -> numWorker = taskManager->maxCPU;
23 createWorkers(context, taskManager, taskManagerImpl); 23 createWorkers(context, taskManager, taskManagerImpl);
24 taskManager->taskManager = (union Data*)taskManagerImpl; 24 taskManager->taskManager = (union Data*)taskManagerImpl;
25 printf ("create taskManagerImpl %p workers %p\n",taskManagerImpl, taskManagerImpl->workers);
26 printf ("create taskManager %p\n",taskManager);
27 return taskManager; 25 return taskManager;
28 } 26 }
29 27
30 void createWorkers(struct Context* context, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) { 28 void createWorkers(struct Context* context, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) {
31 int i = 0; 29 int i = 0;
36 } 34 }
37 for (;i<taskManager->cpu;i++) { 35 for (;i<taskManager->cpu;i++) {
38 #ifdef USE_CUDAWorker 36 #ifdef USE_CUDAWorker
39 Queue* queue = createSynchronizedQueue(context); 37 Queue* queue = createSynchronizedQueue(context);
40 // taskManagerImpl->workers[i] = (Worker*)createCUDAWorker(context, i, queue,0); 38 // taskManagerImpl->workers[i] = (Worker*)createCUDAWorker(context, i, queue,0);
41 printf("createWorkers q %p\n", queue );
42 taskManagerImpl->workers[i] = (Worker*)queue; 39 taskManagerImpl->workers[i] = (Worker*)queue;
43 printf("createWorkers im %p\n", taskManagerImpl );
44 printf ("createWorkers workers %p\n",taskManagerImpl->workers);
45 #else 40 #else
46 Queue* queue = createSynchronizedQueue(context); 41 Queue* queue = createSynchronizedQueue(context);
47 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue); 42 taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context, i, queue);
48 #endif 43 #endif
49 } 44 }
55 50
56 __code createTask(struct TaskManager* taskManager) { 51 __code createTask(struct TaskManager* taskManager) {
57 TaskManager *t = (TaskManager *)taskManager->taskManager; 52 TaskManager *t = (TaskManager *)taskManager->taskManager;
58 TaskManagerImpl *im = (TaskManagerImpl *)t->taskManager; 53 TaskManagerImpl *im = (TaskManagerImpl *)t->taskManager;
59 54
60 printf ("createTask im %p 1 worker %p q %p \n",im, im->workers, im->workers[0]->tasks);
61
62 taskManager->context = NEW(struct Context); 55 taskManager->context = NEW(struct Context);
63 initContext(taskManager->context); 56 initContext(taskManager->context);
64 taskManager->context->taskManager = taskManager; 57 taskManager->context->taskManager = taskManager;
65 struct Queue* tasks = im->workers[0]->tasks; 58 struct Queue* tasks = im->workers[0]->tasks;
66 printf ("createTask q %p\n",tasks);
67 goto meta(context, C_setWorker); 59 goto meta(context, C_setWorker);
68 } 60 }
69 61
70 __code setWorker(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { 62 __code setWorker(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) {
71 task->workerId = taskManager->sendWorkerIndex; 63 task->workerId = taskManager->sendWorkerIndex;
79 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); 71 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
80 goto setWorker(context, taskManager, Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next); 72 goto setWorker(context, taskManager, Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next);
81 } 73 }
82 74
83 __code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) { 75 __code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) {
84 printf ("2 %p\n",taskManager->workers[0]->tasks);
85 if (task->idgCount == 0) { 76 if (task->idgCount == 0) {
86 // enqueue activeQueue 77 // enqueue activeQueue
87 queue->queue = (union Data*)taskManager->activeQueue; 78 queue->queue = (union Data*)taskManager->activeQueue;
88 } else { 79 } else {
89 // enqueue waitQueue 80 // enqueue waitQueue
94 goto meta(context, queue->queue->Queue.put); 85 goto meta(context, queue->queue->Queue.put);
95 } 86 }
96 87
97 __code spawnTaskManager_stub(struct Context* context) { 88 __code spawnTaskManager_stub(struct Context* context) {
98 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); 89 TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
99 printf ("3 %p\n",taskManager->workers[0]->tasks);
100 pthread_mutex_lock(&taskManager->mutex); 90 pthread_mutex_lock(&taskManager->mutex);
101 goto spawnTaskManager(context, 91 goto spawnTaskManager(context,
102 taskManager, 92 taskManager,
103 Gearef(context, Queue), 93 Gearef(context, Queue),
104 Gearef(context, TaskManager)->context, 94 Gearef(context, TaskManager)->context,
124 } 114 }
125 115
126 __code taskSend1(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) { 116 __code taskSend1(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) {
127 struct Queue* tasks = taskManager->workers[task->workerId]->tasks; 117 struct Queue* tasks = taskManager->workers[task->workerId]->tasks;
128 queue->queue = (union Data*)tasks; 118 queue->queue = (union Data*)tasks;
129 printf("taskSend1 workerid %d %p workers %p q %p \n" , task->workerId, taskManager, taskManager->workers, queue->queue);
130 queue->data = (union Data*)task; 119 queue->data = (union Data*)task;
131 queue->next = next; 120 queue->next = next;
132 goto meta(context, tasks->put); 121 goto meta(context, tasks->put);
133 } 122 }
134 123