Mercurial > hg > GearsTemplate
changeset 182:57a11c15ff4c
Add queue_test
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Dec 2016 21:33:11 +0900 |
parents | 78b28c8ffff2 |
children | dec50dd624c7 |
files | src/parallel_execution/TaskManager.c src/parallel_execution/context.c src/parallel_execution/context.h src/parallel_execution/main.c src/parallel_execution/queue.c src/parallel_execution/queue.h src/parallel_execution/test/CMakeLists.txt src/parallel_execution/test/queue_test.c |
diffstat | 8 files changed, 117 insertions(+), 156 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/TaskManager.c Tue Dec 13 02:12:49 2016 +0000 +++ b/src/parallel_execution/TaskManager.c Wed Dec 14 21:33:11 2016 +0900 @@ -1,34 +1,20 @@ #include "context.h" #include "stack.h" +#include "queue.h" #include "origin_cs.h" #include <stdio.h> union Data* createTaskManager(struct Context* context) { struct TaskManager* taskManager = &ALLOCATE(context, TaskManager)->taskManager; struct TaskManager* taskManagerImpl = &ALLOCATE(context, TaskManagerImpl)->taskManagerImpl; - - taskManager->taskManager = (union Data*)taskManager; - taskManagerImpl->top = NULL; + taskManagerImpl -> activeQueue = createSynchronizedQueue(context); + taskManagerImpl -> waitQueue = createSynchronizedQueue(context); + taskManager->taskManager = (union Data*)taskManagerImpl; taskManager->spawn = C_spawnTaskManager; taskManager->shutdown = C_shutdownTaskManager; return (union Data*)(taskManager); } -void printStack1(union Data* data) { - struct Node* node = &data->element.data->node; - if (node == NULL) { - printf("NULL"); - } else { - printf("key = %d ,", node->key); - printStack1((union Data*)data->element.next); - } -} - -void printStack(union Data* data) { - printStack1(data); - printf("\n"); -} - __code spawnTaskManager(struct Context* context, struct Task* task, struct Element* element, struct Queue* queue, struct Queue* activeQueue, struct Queue* waitQueue) { if (task->idsCount == 0) { // enqueue activeQueue @@ -50,7 +36,7 @@ &context->data[D_WaitQueue]->Queue); } -__code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { +__code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { int i = loopCounter->i; if (i < worker->num) { @@ -67,125 +53,6 @@ goto meta(context, EndTime); } -__code taskManager_stub(struct Context* context) { - goto taskManager(context, &context->data[D_LoopCounter]->loopCounter, &context->data[D_Worker]->worker); -} - -__code clearTaskManager(struct Context* context, struct SingleLinkedStack* stack,enum Code next) { - stack->top = NULL; - goto meta(context, next); -} - -__code clearTaskManager_stub(struct Context* context) { - goto clearTaskManager(context, (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack, context->data[D_Stack]->stack.next); -} - -__code pushTaskManager(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) { - element->next = stack->top; - element->data = data; - stack->top = element; - goto meta(context, next); -} - -__code pushTaskManager_stub(struct Context* context) { - struct Element* element = &ALLOCATE(context, Element)->element; - goto pushTaskManager(context, - (struct TaskManager *)context->data[D_Stack]->stack.stack->stack.stack, - element, - context->data[D_Stack]->stack.data, - context->data[D_Stack]->stack.next); -} - -__code popTaskManager(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) { - if (stack->top) { - *data = stack->top->data; - stack->top = stack->top->next; - } else { - *data = NULL; - } - goto meta(context, next); -} - -__code popTaskManager_stub(struct Context* context) { - goto popTaskManager(context, - (struct TaskManager *)context->data[D_Stack]->stack.stack->stack.stack, - &context->data[D_Stack]->stack.data, - context->data[D_Stack]->stack.next); -} - -__code pop2TaskManager(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) { - if (stack->top) { - *data = stack->top->data; - stack->top = stack->top->next; - } else { - *data = NULL; - } - if (stack->top) { - *data1 = stack->top->data; - stack->top = stack->top->next; - } else { - *data1 = NULL; - } - goto meta(context, next); +__code shutdownTaskManager_stub(struct Context* context) { + goto shutdownTaskManager(context, &context->data[D_LoopCounter]->loopCounter, &context->data[D_Worker]->worker); } - -__code pop2TaskManager_stub(struct Context* context) { - goto pop2TaskManager(context, - (struct TaskManager *)context->data[D_Stack]->stack.stack->stack.stack, - &context->data[D_Stack]->stack.data, - &context->data[D_Stack]->stack.data1, - context->data[D_Stack]->stack.next); -} - -__code getTaskManager(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) { - if (stack->top) - *data = stack->top->data; - else - *data = NULL; - goto meta(context, next); -} - -__code getTaskManager_stub(struct Context* context) { - goto getTaskManager(context, - (struct TaskManager *)context->data[D_Stack]->stack.stack->stack.stack, - &context->data[D_Stack]->stack.data, - context->data[D_Stack]->stack.next); -} - -__code get2TaskManager(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) { - if (stack->top) { - *data = stack->top->data; - if (stack->top->next) { - *data1 = stack->top->next->data; - } else { - *data1 = NULL; - } - } else { - *data = NULL; - *data1 = NULL; - } - goto meta(context, next); -} - -__code get2TaskManager_stub(struct Context* context) { - goto get2TaskManager(context, - (struct TaskManager *)context->data[D_Stack]->stack.stack->stack.stack, - &context->data[D_Stack]->stack.data, - &context->data[D_Stack]->stack.data1, - context->data[D_Stack]->stack.next); -} - -__code isEmptyTaskManager(struct Context* context, struct SingleLinkedStack* stack, enum Code next,enum Code whenEmpty) { - if (stack->top) - goto meta(context, next); - else - goto meta(context, whenEmpty); -} - -__code isEmptyTaskManager_stub(struct Context* context) { - goto isEmptyTaskManager(context, - (struct TaskManager *)context->data[D_Stack]->stack.stack->stack.stack, - context->data[D_Stack]->stack.next, - context->data[D_Stack]->stack.whenEmpty); -} -
--- a/src/parallel_execution/context.c Tue Dec 13 02:12:49 2016 +0000 +++ b/src/parallel_execution/context.c Wed Dec 14 21:33:11 2016 +0900 @@ -60,6 +60,10 @@ extern __code putQueue4_stub(struct Context*); extern __code getTask1_stub(struct Context*); extern __code getTask2_stub(struct Context*); +extern __code queue_test1_stub(struct Context*); +extern __code queue_test2_stub(struct Context*); +extern __code queue_test3_stub(struct Context*); +extern __code queue_test4_stub(struct Context*); extern __code spawnTask_stub(struct Context*); extern __code twice_stub(struct Context*); extern __code start_time_stub(struct Context*); @@ -73,6 +77,8 @@ extern __code putSynchronizedQueue_stub(struct Context *); extern __code takeSynchronizedQueue_stub(struct Context *); extern __code isEmptySynchronizedQueue_stub(struct Context *); +extern __code spawnTaskManager_stub(struct Context*); +extern __code shutdownTaskManager_stub(struct Context*); __code initContext(struct Context* context) { context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; @@ -153,6 +159,10 @@ context->code[C_getTask1] = getTask1_stub; context->code[C_getTask2] = getTask2_stub; context->code[SpawnTask] = spawnTask_stub; + context->code[C_QueueTest1] = queue_test1_stub; + context->code[C_QueueTest2] = queue_test2_stub; + context->code[C_QueueTest3] = queue_test3_stub; + context->code[C_QueueTest4] = queue_test4_stub; context->code[Twice] = twice_stub; context->code[StartTime] = start_time_stub; context->code[EndTime] = end_time_stub;
--- a/src/parallel_execution/context.h Tue Dec 13 02:12:49 2016 +0000 +++ b/src/parallel_execution/context.h Wed Dec 14 21:33:11 2016 +0900 @@ -111,6 +111,10 @@ C_getRedBlackTree, C_removeRedBlackTree, C_clearRedBlackTree, + C_QueueTest1, + C_QueueTest2, + C_QueueTest3, + C_QueueTest4, SpawnTask, Twice, StartTime, @@ -131,6 +135,8 @@ D_Stack, D_RedBlackTree, D_Tree, + D_TaskManager, + D_TaskManagerImpl, D_Task, D_Traverse, D_RotateTree, @@ -177,7 +183,11 @@ enum Code taskSend; enum Code shutdown; struct Worker* workers; - } + } taskManager; + struct TaskManagerImpl { + struct Queue *activeQueue; + struct Queue *waitQueue; + } taskManagerImpl; struct Worker { int id; struct Context* contexts; @@ -200,7 +210,7 @@ enum Code code; enum Code next; struct Queue* args; - } + } main; struct Task { enum Code code; struct Queue* dataGears; @@ -216,11 +226,11 @@ enum Code take; enum Code isEmpty; enum Code next; - } Queue; + } queue; struct SingleLinkedQueue { struct Element* top; struct Element* last; - } SingleLinkedQueue; + } singleLinkedQueue; // Stack Interface struct Stack { union Data* stack;
--- a/src/parallel_execution/main.c Tue Dec 13 02:12:49 2016 +0000 +++ b/src/parallel_execution/main.c Wed Dec 14 21:33:11 2016 +0900 @@ -15,7 +15,7 @@ void print_queue(struct Element* element) { while (element) { - printf("%d\n", ((struct Task *)(element->data))->key); + printf("%d\n", ((struct Task *)(element->data))); element = element->next; } } @@ -111,13 +111,8 @@ Gearef(context, Tree)); } -__code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct Queue* waitI, struct Element* element) { - int i = loopCounter->i; - +__code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Element* element) { task->code = Twice; - task->key = i; - task->waitMe = waitMe; - task->waitI = waitI; task->idsCount = 0; element->data = (union Data *)task; @@ -130,13 +125,9 @@ __code createTask1_stub(struct Context* context) { Task* task = &ALLOCATE(context, Task)->Task; - Queue* waitMe = &ALLOCATE(context, Queue)->Queue; - Queue* waitI = &ALLOCATE(context, Queue)->Queue; goto createTask1(context, &context->data[D_LoopCounter]->loopCounter, task, - waitMe, - waitI, &context->data[D_Element]->element); }
--- a/src/parallel_execution/queue.c Tue Dec 13 02:12:49 2016 +0000 +++ b/src/parallel_execution/queue.c Wed Dec 14 21:33:11 2016 +0900 @@ -1,4 +1,3 @@ -#include "context.h" #include "queue.h" #include "origin_cs.h" #include <stdio.h>
--- a/src/parallel_execution/queue.h Tue Dec 13 02:12:49 2016 +0000 +++ b/src/parallel_execution/queue.h Wed Dec 14 21:33:11 2016 +0900 @@ -1,3 +1,4 @@ +#include "context.h" extern union Data* createSingleLinkedQueue(struct Context* context); extern __code putSingleLinkedQueue_stub(struct Context* context);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/test/CMakeLists.txt Wed Dec 14 21:33:11 2016 +0900 @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8) + +# -DUSE_CUDA +# add_definitions("-Wall -g -O") +add_definitions("-Wall -g") + +set(CMAKE_C_COMPILER $ENV{CBC_COMPILER}) + +add_executable(queue_test + queue_test.c + ../context.c + ../queue.c + ../origin_cs.c +)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/test/queue_test.c Wed Dec 14 21:33:11 2016 +0900 @@ -0,0 +1,69 @@ +#include "../queue.h" +#include "../context.h" +#include "../origin_cs.h" +#include <assert.h> + + +__code queue_test1(struct Context* context, struct Task* task, struct Queue* queue) { + task->code = C_QueueTest1; + queue->next = C_QueueTest2; + queue->data = (union Data*)task; + goto meta(context, queue->queue->queue.put); +} + +__code queue_test1_stub(struct Context* context) { + Task* task = &ALLOCATE(context, Task)->Task; + struct Queue* queue = &(createSingleLinkedQueue(context)->queue); + assert(queue->queue->singleLinkedQueue.top == NULL); + assert(queue->queue->singleLinkedQueue.last == NULL); + context->data[D_Queue]->queue.queue = (union Data*)queue; + goto queue_test1(context, + task, + &context->data[D_Queue]->queue); +} + +__code queue_test2(struct Context* context, struct Task* task, struct Queue* queue) { + task->code = C_QueueTest2; + queue->next = C_QueueTest3; + queue->data = (union Data*)task; + goto meta(context, queue->queue->queue.put); +} + +__code queue_test2_stub(struct Context* context) { + assert(((struct Task)context->data[D_Queue]->queue.queue->queue.queue->singleLinkedQueue.top->data)->code == C_QueueTest1) + assert(((struct Task)context->data[D_Queue]->queue.queue->queue.queue->singleLinkedQueue.top->data)->code == C_QueueTest1) + Task* task = &ALLOCATE(context, Task)->Task; + goto queue_test2(context, + task, + &context->data[D_Queue]->queue->queue); +} + +__code queue_test3(struct Context* context, struct Queue* queue) { + queue->next = C_QueueTest4; + goto meta(context, queue->queue->take) +} + +__code queue_test3_stub(struct Context* context) { + assert(((struct Task)context->data[D_Queue]->queue.queue->queue.queue->singleLinkedQueue.top->data)->code == C_QueueTest2) + assert(((struct Task)context->data[D_Queue]->queue.queue->queue.queue->singleLinkedQueue.top->data)->code == C_QueueTest1) + goto queue_test3(context, + &context->data[D_Queue]->queue); +} + +__code queue_test4(struct Context* context) { + goto meta(context, Exit); +} + +__code queue_test4_stub(struct Context* context) { + assert(((struct Task)context->data[D_Queue]->queue.queue.data)->code == C_QueueTest1) + assert(((struct Task)context->data[D_Queue]->queue.queue.last->data)->code == C_QueueTest2) + goto queue_test4(context, + &context->data[D_Queue]->queue->queue); +} + +int main(int argc, char const* argv[]) { + struct Context* main_context = NEW(struct Context); + initContext(main_context); + main_context->next = C_QueueTest1; + goto start_code(main_context); +}