Mercurial > hg > GearsTemplate
changeset 248:1ede5390cda2
Fix segmentation fault but not multi thread running
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Jan 2017 16:55:53 +0900 |
parents | ce262b2c1daf |
children | afa1e02e4386 |
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, 25 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/main.c Wed Jan 25 04:14:50 2017 +0900 +++ b/src/parallel_execution/main.c Wed Jan 25 16:55:53 2017 +0900 @@ -33,7 +33,7 @@ loopCounter->tree = &createRedBlackTree(context)->Tree; loopCounter->i = 0; taskManager->taskManager = (union Data*)&createTaskManager(context, cpu_num, 0, 0)->TaskManager; - goto meta(context, C_createData1); + goto meta(context, C_createTask1); } __code initDataGears_stub(struct Context* context) { @@ -51,7 +51,8 @@ /* puts("result"); */ time->next = C_code2; - goto meta(context, C_start_time); + goto meta(context, C_exit_code); + //goto meta(context, C_start_time); } __code code1_stub(struct Context* context) { @@ -153,9 +154,9 @@ goto meta(context, taskManager->taskManager->TaskManager.spawn); } - loopCounter->i = 0; - goto meta(context, C_code1); + taskManager->next = C_code1; + goto meta(context, taskManager->taskManager->TaskManager.shutdown); } __code createTask2_stub(struct Context* context) { @@ -167,18 +168,6 @@ array); } -__code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { - loopCounter->i = 0; - - Time *t = &context->data[D_Time]->Time; - t->next = C_code2; - goto meta(context, C_end_time); -} - -__code taskManager_stub(struct Context* context) { - goto taskManager(context, &context->data[D_LoopCounter]->LoopCounter, &context->data[D_Worker]->Worker); -} - void init(int argc, char** argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-cpu") == 0)
--- a/src/parallel_execution/taskManager.c Wed Jan 25 04:14:50 2017 +0900 +++ b/src/parallel_execution/taskManager.c Wed Jan 25 16:55:53 2017 +0900 @@ -109,7 +109,7 @@ __code taskSend(struct Context* context, TaskManagerImpl* taskManager, Queue* queue) { queue->queue = (union Data*)taskManager->activeQueue; queue->next = C_taskSend1; - goto meta(context, taskManager->activeQueue->put); + goto meta(context, taskManager->activeQueue->take); } __code taskSend_stub(struct Context* context) { @@ -131,12 +131,16 @@ goto taskSend1(context, taskManager, Gearef(context, Queue), Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next); } -__code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl) { +__code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, TaskManager* taskManager, TaskManagerImpl* taskManagerImpl, Queue* queue, enum Code next) { int i = loopCounter->i; if (taskManager->cpu <= i && i < taskManager->maxCPU) { + struct Queue* tasks = taskManagerImpl->workers[i]->tasks; + queue->queue = (union Data*)tasks; + queue->data = NULL; + queue->next = next; + goto meta(context, tasks->put); pthread_join(taskManagerImpl->workers[i]->worker->CPUWorker.thread, NULL); loopCounter->i++; - goto meta(context, C_shutdownTaskManager); } @@ -146,5 +150,5 @@ __code shutdownTaskManager_stub(struct Context* context) { TaskManagerImpl* taskManagerImpl = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); - goto shutdownTaskManager(context, Gearef(context, LoopCounter), Gearef(context, TaskManager), taskManagerImpl); + goto shutdownTaskManager(context, Gearef(context, LoopCounter), Gearef(context, TaskManager), taskManagerImpl, Gearef(context, Queue), Gearef(context, TaskManager)->next); }
--- a/src/parallel_execution/twice.c Wed Jan 25 04:14:50 2017 +0900 +++ b/src/parallel_execution/twice.c Wed Jan 25 16:55:53 2017 +0900 @@ -3,9 +3,8 @@ #include "context.h" #include "origin_cs.h" -__code twice(struct Context* context, struct LoopCounter* loopCounter, int index, int prefix, int* array, enum Code next) { +__code twice(struct Context* context, struct LoopCounter* loopCounter, int index, int prefix, int* array, Context* workerContext) { int i = loopCounter->i; - if (i < prefix) { array[i+index*prefix] = array[i+index*prefix]*2; loopCounter->i++; @@ -14,11 +13,10 @@ } loopCounter->i = 0; - - //stack_pop(context->code_stack, &context->next); - goto meta(context, next); + goto meta(workerContext, workerContext->next); } __code twice_stub(struct Context* context) { - goto twice(context, NULL, 0, 0, NULL, 0); + Context* workerContext = context->worker->worker->CPUWorker.context; + goto twice(context, Gearef(context, LoopCounter), 0, 0, NULL, workerContext); }
--- a/src/parallel_execution/worker.c Wed Jan 25 04:14:50 2017 +0900 +++ b/src/parallel_execution/worker.c Wed Jan 25 16:55:53 2017 +0900 @@ -22,31 +22,33 @@ 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) { queue->queue = (union Data*)worker->tasks; - queue->next = C_getTask1; - goto meta(context, queue->take); + queue->next = C_getTask; + goto meta(context, worker->tasks->take); } __code taskReceiveWorker_stub(struct Context* context) { + CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); + pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex); goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); } -__code getTask1(struct Context* context, Worker* worker, struct Context* task) { +__code getTask(struct Context* context, Worker* worker, struct Context* task) { if (!task) return; // end thread task->worker = worker; + context->next = C_taskReceiveWorker; // set CG after task exec goto meta(task, task->next); } -__code getTask1_stub(struct Context* context) { +__code getTask_stub(struct Context* context) { Worker* worker = &Gearef(context,Worker)->worker->Worker; Context* task = &Gearef(context, Queue)->data->context; - goto getTask1(context, worker, task); + goto getTask(context, worker, task); } #ifdef USE_CUDA