Mercurial > hg > GearsTemplate
changeset 247:ce262b2c1daf
Fix createTask for main
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Jan 2017 04:14:50 +0900 |
parents | 421ea91dd76c |
children | 1ede5390cda2 |
files | src/parallel_execution/main.c src/parallel_execution/taskManager.c src/parallel_execution/twice.c src/parallel_execution/worker.c |
diffstat | 4 files changed, 58 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/main.c Wed Jan 25 03:07:59 2017 +0900 +++ b/src/parallel_execution/main.c Wed Jan 25 04:14:50 2017 +0900 @@ -6,7 +6,7 @@ #include "origin_cs.h" extern union Data* createRedBlackTree(struct Context* context); -extern union Data* createTaskManager(struct Context* context); +extern union Data* createTaskManager(struct Context* context, int numCPU, int numGPU, int numIO); extern void allocator(struct Context* context); int cpu_num = 1; @@ -32,7 +32,7 @@ __code initDataGears(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) { loopCounter->tree = &createRedBlackTree(context)->Tree; loopCounter->i = 0; - taskManager->taskManager = (union Data*)&createTaskManager(context)->TaskManager; + taskManager->taskManager = (union Data*)&createTaskManager(context, cpu_num, 0, 0)->TaskManager; goto meta(context, C_createData1); } @@ -120,23 +120,51 @@ Gearef(context, Tree)); } -__code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Task* task) { - task->code = C_twice; - task->idsCount = 0; +__code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager) { + int i = loopCounter->i; -// taskManager->task = task; - taskManager->next = C_createData1; - loopCounter->i++; + if ((length/split*i) < length) { + taskManager->next = C_createTask2; + goto meta(context, taskManager->taskManager->TaskManager.createTask); + } - goto meta(context, taskManager->taskManager->TaskManager.spawn); + loopCounter->i = 0; + goto meta(context, C_code1); } __code createTask1_stub(struct Context* context) { - Task* task = &ALLOCATE(context, Task)->Task; goto createTask1(context, Gearef(context, LoopCounter), + Gearef(context, TaskManager)); +} + +__code createTask2(Context* context, LoopCounter* loopCounter, TaskManager* taskManager, Context* task, Array* array) { + int i = loopCounter->i; + + if ((length/split*i) < length) { + array->index = i; + array->prefix = length/split; + array->array = array_ptr; + task->idgCount = 0; + task->next = C_twice; + // task->data[task->idg] = (union Data*)array; + taskManager->next = C_createTask1; + loopCounter->i++; + + goto meta(context, taskManager->taskManager->TaskManager.spawn); + } + + loopCounter->i = 0; + goto meta(context, C_code1); +} + +__code createTask2_stub(struct Context* context) { + Array* array = &ALLOCATE(context, Array)->Array; + goto createTask2(context, + Gearef(context, LoopCounter), Gearef(context, TaskManager), - task); + Gearef(context, TaskManager)->context, + array); } __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { @@ -175,11 +203,6 @@ initContext(main_context); main_context->next = C_initDataGears; - struct Context* worker_contexts = NEWN(cpu_num, struct Context); - - for (int i = 0;i<cpu_num;i++) - initContext(&worker_contexts[i]); - goto start_code(main_context); }
--- a/src/parallel_execution/taskManager.c Wed Jan 25 03:07:59 2017 +0900 +++ b/src/parallel_execution/taskManager.c Wed Jan 25 04:14:50 2017 +0900 @@ -5,7 +5,7 @@ #include "origin_cs.h" #include <stdio.h> -void createWorkers(Context* context, TaskManager * taskManeger); +void createWorkers(Context* context, TaskManager* taskManeger, TaskManagerImpl* taskManagerImpl); union Data* createTaskManager(struct Context* context, int numCPU, int numGPU, int numIO) { struct TaskManager* taskManager = &ALLOCATE(context, TaskManager)->TaskManager; @@ -19,18 +19,17 @@ taskManager->createTask = C_createTask; taskManager->spawn = C_spawnTaskManager; taskManager->shutdown = C_shutdownTaskManager; - createWorkers(context, taskManager); struct TaskManagerImpl* taskManagerImpl = &ALLOCATE(context, TaskManagerImpl)->TaskManagerImpl; taskManager->taskManager = (union Data*)taskManagerImpl; taskManagerImpl -> activeQueue = &createSingleLinkedQueue(context)->Queue; taskManagerImpl -> taskQueue = &createSingleLinkedQueue(context)->Queue; taskManagerImpl -> numWorker = taskManager->maxCPU; + createWorkers(context, taskManager, taskManagerImpl); return (union Data*)(taskManager); } -void createWorkers(Context* context, TaskManager* taskManager) { +void createWorkers(Context* context, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) { int i = 0; - TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context,TaskManager,taskManager); taskManagerImpl->workers = (Worker**)ALLOC_ARRAY(context, Worker, taskManager->maxCPU); for (;i<taskManager->gpu;i++) { Queue* queue = &createSynchronizedQueue(context)->Queue; @@ -52,14 +51,14 @@ __code createTask(struct Context* context, TaskManager* taskManager) { taskManager->context = NEW(struct Context); initContext(taskManager->context); - goto meta(context, C_setRunWorker); + goto meta(context, C_setWorker); } __code createTask_stub(struct Context* context) { - goto createTask(context,Gearef(context,TaskManager)); + goto createTask(context, Gearef(context,TaskManager)); } -__code setRunWorker(struct Context* context, TaskManagerImpl* taskManager, Context* task, enum Code next) { +__code setWorker(struct Context* context, TaskManagerImpl* taskManager, Context* task, enum Code next) { task->workerId = taskManager->sendWorkerIndex; if(++taskManager->sendWorkerIndex >= taskManager->numWorker) { taskManager->sendWorkerIndex = 0; @@ -67,9 +66,9 @@ goto meta(context, next); } -__code setRunWorker_stub(struct Context* context) { +__code setWorker_stub(struct Context* context) { TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - goto setRunWorker(context, taskManager, Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next); + goto setWorker(context, taskManager, Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next); } __code spawnTaskManager(struct Context* context, struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, enum Code next) { @@ -96,16 +95,15 @@ } -__code spawnTaskManager1(struct Context* context, struct TaskManagerImpl* taskManager, enum Code next) { +__code spawnTaskManager1(struct Context* context, struct TaskManagerImpl* taskManager) { pthread_mutex_unlock(&taskManager->mutex); - goto meta(context, next); + goto meta(context, C_taskSend); } __code spawnTaskManager1_stub(struct Context* context) { TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); goto spawnTaskManager1(context, - taskManager, - Gearef(context, TaskManager)->next); + taskManager); } __code taskSend(struct Context* context, TaskManagerImpl* taskManager, Queue* queue) {
--- a/src/parallel_execution/twice.c Wed Jan 25 03:07:59 2017 +0900 +++ b/src/parallel_execution/twice.c Wed Jan 25 04:14:50 2017 +0900 @@ -20,5 +20,5 @@ } __code twice_stub(struct Context* context) { - goto twice(context, NULL, 0, 0, NULL,0); + goto twice(context, NULL, 0, 0, NULL, 0); }
--- a/src/parallel_execution/worker.c Wed Jan 25 03:07:59 2017 +0900 +++ b/src/parallel_execution/worker.c Wed Jan 25 04:14:50 2017 +0900 @@ -21,18 +21,19 @@ CPUWorker* cpuWorker = (CPUWorker*)worker->worker; cpuWorker->context = NEW(struct Context); initContext(cpuWorker->context); + Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex); goto meta(cpuWorker->context, C_taskReceiveWorker); } -__code taskReceiveWorker(struct Context* context, Worker* worker) { - Queue* queue = worker->tasks; +__code taskReceiveWorker(struct Context* context, Worker* worker, Queue* queue) { + queue->queue = (union Data*)worker->tasks; queue->next = C_getTask1; goto meta(context, queue->take); } __code taskReceiveWorker_stub(struct Context* context) { - goto taskReceiveWorker(context, Gearef(context, Worker)); + goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); } __code getTask1(struct Context* context, Worker* worker, struct Context* task) { @@ -43,9 +44,9 @@ } __code getTask1_stub(struct Context* context) { - Worker* worker = Gearef(context,Worker); - Context* task = &worker->tasks->data->context; - goto getTask1(context,worker,task); + Worker* worker = &Gearef(context,Worker)->worker->Worker; + Context* task = &Gearef(context, Queue)->data->context; + goto getTask1(context, worker, task); } #ifdef USE_CUDA