Mercurial > hg > GearsTemplate
changeset 482:5859bed4edff
Refactoring spawnTasks method
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 29 Dec 2017 04:42:44 +0900 |
parents | a517b11c37f7 |
children | 9098ec0a9e6b |
files | src/parallel_execution/TaskManager.h src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/context.h src/parallel_execution/generate_context.pl src/parallel_execution/generate_stub.pl |
diffstat | 5 files changed, 55 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/TaskManager.h Thu Dec 28 23:31:23 2017 +0900 +++ b/src/parallel_execution/TaskManager.h Fri Dec 29 04:42:44 2017 +0900 @@ -1,9 +1,9 @@ typedef struct TaskManager<Impl>{ union Data* taskManager; struct Context* task; - struct Context** tasks; + struct Element* taskList; __code spawn(Impl* taskManager, struct Context* task, __code next(...)); - __code spawnTasks(Impl* taskManagerImpl, struct Context** tasks, __code next1(...)); + __code spawnTasks(Impl* taskManagerImpl, struct Element* taskList, __code next1(...)); __code setWaitTask(Impl* taskManagerImpl, struct Context* task, __code next(...)); __code shutdown(Impl* taskManagerImpl, __code next(...)); __code incrementTaskCount(Impl* taskManagerImpl, __code next(...));
--- a/src/parallel_execution/TaskManagerImpl.cbc Thu Dec 28 23:31:23 2017 +0900 +++ b/src/parallel_execution/TaskManagerImpl.cbc Fri Dec 29 04:42:44 2017 +0900 @@ -25,7 +25,6 @@ taskManagerImpl->gpu = numIO; taskManagerImpl->cpu = numIO+numGPU; taskManagerImpl->maxCPU = numIO+numGPU+numCPU; - taskManagerImpl->taskQueue = createSingleLinkedQueue(context); taskManagerImpl->numWorker = taskManagerImpl->maxCPU; taskManagerImpl->sendGPUWorkerIndex = taskManagerImpl->gpu; taskManagerImpl->sendCPUWorkerIndex = taskManagerImpl->cpu; @@ -57,59 +56,45 @@ } } -__code spawnTasksTaskManagerImpl(struct TaskManagerImpl* taskManager, struct Queue* tasks, __code next1(...)) { - goto tasks->isEmpty(spawnTasksTaskManagerImpl1, spawnTasksTaskManagerImpl3); +__code spawnTasksTaskManagerImpl(struct TaskManagerImpl* taskManager, struct Element* taskList, __code next1(...)) { + taskManager->taskList = taskList; + goto spawnTasksTaskManagerImpl1(); } -__code spawnTasksTaskManagerImpl_stub(struct Context* context) { - TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - Queue* tasks = Gearef(context, TaskManager)->tasks; - enum Code next1 = Gearef(context, TaskManager)->next1; - goto spawnTasksTaskManagerImpl(context, taskManager, tasks, next1); -} - -__code spawnTasksTaskManagerImpl1(struct TaskManagerImpl* taskManager, struct Queue* tasks, __code next1(...)) { - goto tasks->take(spawnTasksTaskManagerImpl2); +__code spawnTasksTaskManagerImpl1(struct TaskManagerImpl* taskManagerImpl, struct TaskManager* taskManager) { + if (taskManagerImpl->taskList == NULL) { + goto spawnTasksTaskManagerImpl2(); + } + struct Context* task = (struct Context*)taskManagerImpl->taskList->data; + taskManagerImpl->taskList = taskManagerImpl->taskList->next; + goto taskManager->setWaitTask(task, spawnTasksTaskManagerImpl1); } __code spawnTasksTaskManagerImpl1_stub(struct Context* context) { - TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - Queue* tasks = Gearef(context, TaskManager)->tasks; - enum Code next1 = Gearef(context, TaskManager)->next1; - goto spawnTasksTaskManagerImpl1(context, taskManager, tasks, next1); -} - -__code spawnTasksTaskManagerImpl2(struct TaskManagerImpl* taskManagerImpl, struct Context* task, struct TaskManager* taskManager) { - task->taskManager = taskManager; - goto taskManager->setWaitTask(task, spawnTasksTaskManagerImpl); + TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); + TaskManager* taskManager = &Gearef(context, TaskManager)->taskManager->TaskManager; + goto spawnTasksTaskManagerImpl1(context, taskManagerImpl, taskManager); } -__code spawnTasksTaskManagerImpl2_stub(struct Context* context) { - TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - Context* task = (struct Context*)Gearef(context, Queue)->data; - TaskManager* taskManager = &Gearef(context, TaskManager)->taskManager->TaskManager; - goto spawnTasksTaskManagerImpl2(context, taskManagerImpl, task, taskManager); +__code spawnTasksTaskManagerImpl2(struct TaskManagerImpl* taskManager, struct Element* taskList, __code next1(...)) { + taskManager->taskList = taskList; + goto spawnTasksTaskManagerImpl3(); } -__code spawnTasksTaskManagerImpl3(struct TaskManagerImpl* taskManager, __code next1(...)) { - struct Queue* queue = taskManager->taskQueue; - goto queue->isEmpty(spawnTasksTaskManagerImpl4, next1(...)); -} - -__code spawnTasksTaskManagerImpl4(struct TaskManagerImpl* taskManager, __code next1(...)) { - struct Queue* queue = taskManager->taskQueue; - goto queue->take(spawnTasksTaskManagerImpl5); -} - -__code spawnTasksTaskManagerImpl5(struct TaskManagerImpl* taskManagerImpl, struct Context* task, struct TaskManager* taskManager) { +__code spawnTasksTaskManagerImpl3(struct TaskManagerImpl* taskManagerImpl, __code next1(...), struct TaskManager* taskManager) { + if (taskManagerImpl->taskList == NULL) { + goto next1(...); + } + struct Context* task = (struct Context*)taskManagerImpl->taskList->data; + taskManagerImpl->taskList = taskManagerImpl->taskList->next; goto taskManager->spawn(task, spawnTasksTaskManagerImpl3); } -__code spawnTasksTaskManagerImpl5_stub(struct Context* context) { +__code spawnTasksTaskManagerImpl3_stub(struct Context* context) { TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - Context* task = (struct Context*)Gearef(context, Queue)->data; + enum Code next1 = Gearef(context, TaskManager)->next1; TaskManager* taskManager = &Gearef(context, TaskManager)->taskManager->TaskManager; - goto spawnTasksTaskManagerImpl5(context, taskManagerImpl, task, taskManager); + goto spawnTasksTaskManagerImpl3(context, taskManagerImpl, next1, taskManager); } __code setWaitTaskTaskManagerImpl(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { @@ -120,17 +105,7 @@ goto queue->put(task, setWaitTaskTaskManagerImpl); } taskManager->loopCounter = 0; - struct Queue* queue = taskManager->taskQueue; - goto queue->put(task, incrementTaskCountTaskManagerImpl); -} - -__code setWaitTaskTaskManagerImpl_stub(struct Context* context) { - TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - struct Context* task = Gearef(context, TaskManager)->task; - goto setWaitTaskTaskManagerImpl(context, - taskManager, - task, - Gearef(context, TaskManager)->next); + goto incrementTaskCountTaskManagerImpl(); } __code incrementTaskCountTaskManagerImpl(struct TaskManagerImpl* taskManager, __code next(...)) { @@ -143,20 +118,33 @@ goto next(...); } -__code spawnTaskManagerImpl(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { +__code spawnTaskManagerImpl(struct TaskManagerImpl* taskManagerImpl, struct Context* task, __code next(...), struct TaskManager* taskManager) { + task->taskManager = taskManager; if (task->idgCount == 0) { // iterator task is normal task until spawned if(task->iterator != NULL && task->iterate == 0) { - pthread_mutex_unlock(&taskManager->mutex); + pthread_mutex_unlock(&taskManagerImpl->mutex); struct Iterator* iterator = task->iterator; - goto iterator->exec(task, taskManager->cpu - taskManager->gpu, next(...)); + goto iterator->exec(task, taskManagerImpl->cpu - taskManagerImpl->gpu, next(...)); } goto taskSend(); } - pthread_mutex_unlock(&taskManager->mutex); + pthread_mutex_unlock(&taskManagerImpl->mutex); goto next(...); } +__code spawnTaskManagerImpl_stub(struct Context* context) { + TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); + struct Context* task = Gearef(context, TaskManager)->task; + TaskManager* taskManager = &Gearef(context, TaskManager)->taskManager->TaskManager; + goto spawnTaskManagerImpl(context, + taskManagerImpl, + task, + Gearef(context, TaskManager)->next, + taskManager); +} + + __code taskSend(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) { // set workerId if (task->gpu) {
--- a/src/parallel_execution/context.h Thu Dec 28 23:31:23 2017 +0900 +++ b/src/parallel_execution/context.h Fri Dec 29 04:42:44 2017 +0900 @@ -108,7 +108,7 @@ int workerId; int gpu; // GPU task struct Context* task; - struct Queue* tasks; + struct Element* taskList; #ifdef USE_CUDAWorker int num_exec; CUmodule module; @@ -156,7 +156,7 @@ enum Code next1; enum Code setWaitTask; struct Context* task; - struct Queue* tasks; + struct Element* taskList; union Data* data; } TaskManager; struct TaskManagerImpl { @@ -167,8 +167,8 @@ int taskCount; pthread_mutex_t mutex; struct Queue* activeQueue; - struct Queue* taskQueue; struct Worker** workers; + struct Element* taskList; int loopCounter; int cpu; int gpu;
--- a/src/parallel_execution/generate_context.pl Thu Dec 28 23:31:23 2017 +0900 +++ b/src/parallel_execution/generate_context.pl Fri Dec 29 04:42:44 2017 +0900 @@ -160,7 +160,6 @@ #include "dataGearInit.c" context->dataNum = $data_num; - context->tasks = createSingleLinkedQueue(context); } EOFEOF @@ -173,7 +172,8 @@ if (context->task == NULL) { goto (context->code[next])(context); } - context->task = NULL; + context->task = NULL; + context->taskList = NULL; goto (context->code[Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks])(context); }
--- a/src/parallel_execution/generate_stub.pl Thu Dec 28 23:31:23 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Fri Dec 29 04:42:44 2017 +0900 @@ -4,7 +4,7 @@ use Getopt::Std; use File::Path qw(make_path); -# interface.cbc +# interface.h # typedef struct Worker { # int id; # struct Context* contexts; @@ -494,10 +494,9 @@ } my $putTask = << "EOFEOF"; ${prev}element = &ALLOCATE(context, Element)->Element; - ${prev}element->next = NULL; ${prev}element->data = (union Data*)context->task; - ${prev}context->tasks->queue->SingleLinkedQueue.last->next = element; - ${prev}context->tasks->queue->SingleLinkedQueue.last = element; + ${prev}element->next = context->taskList; + ${prev}context->taskList = element; EOFEOF print $fd $putTask; next; @@ -520,7 +519,7 @@ print $fd "\t*O_$arg = $v;\n"; } if ($inParGoto) { - print $fd "${prev}Gearef(context, TaskManager)->tasks = context->tasks;\n"; + print $fd "${prev}Gearef(context, TaskManager)->taskList = context->taskList;\n"; print $fd "${prev}Gearef(context, TaskManager)->next1 = C_$next;\n"; print $fd "${prev}goto meta(context, C_$next);\n"; } else { @@ -529,7 +528,7 @@ next; } if ($inParGoto) { - print $fd "${prev}Gearef(context, TaskManager)->tasks = context->tasks;\n"; + print $fd "${prev}Gearef(context, TaskManager)->taskList = context->taskList;\n"; print $fd "${prev}Gearef(context, TaskManager)->next1 = C_$next;\n"; print $fd "${prev}goto meta(context, C_$next);\n"; next;