Mercurial > hg > GearsTemplate
changeset 220:6c0692c9bfed
Fix rb_tree
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 Jan 2017 21:16:29 +0900 |
parents | de1ba77f94b4 |
children | 2454f4392316 |
files | src/parallel_execution/main.c src/parallel_execution/rb_tree.c src/parallel_execution/taskManager.c |
diffstat | 3 files changed, 57 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/main.c Mon Jan 09 05:58:46 2017 +0900 +++ b/src/parallel_execution/main.c Mon Jan 09 21:16:29 2017 +0900 @@ -30,7 +30,18 @@ } } -__code code1(struct Context* context) { +__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; + goto meta(context, C_createData1); +} + +__code initDataGears_stub(struct Context* context) { + goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager)); +} + +__code code1(struct Context* context, struct Time* time) { printf("cpus:\t\t%d\n", cpu_num); printf("length:\t\t%d\n", length); printf("length/task:\t%d\n", length/split); @@ -40,15 +51,12 @@ /* print_tree(context->data[Tree]->tree.root); */ /* puts("result"); */ - context->next = C_createWorker1; - - struct Time *t = &context->data[D_Time]->Time; - t->next = C_createWorker1; + time->next = C_createWorker1; goto meta(context, C_start_time); } __code code1_stub(struct Context* context) { - goto code1(context); + goto code1(context, Gearef(context, Time)); } __code code2(struct Context* context, struct Array* array, struct LoopCounter* loopCounter) { @@ -83,10 +91,6 @@ } __code createData1_stub(struct Context* context) { - LoopCounter* loopCounter = Gearef(context, LoopCounter); - loopCounter->i = 0; - loopCounter->tree = &createRedBlackTree(context)->Tree; - context->data[D_Tree]->Tree.tree = (union Data*)loopCounter->tree; goto createData1(context, Gearef(context, Allocate), Gearef(context, LoopCounter)); } @@ -99,6 +103,8 @@ node->key = i; node->value = (union Data*)array; + + tree->tree = (union Data*)loopCounter->tree; tree->next = C_createTask1; tree->node = node; @@ -128,8 +134,6 @@ __code createTask1_stub(struct Context* context) { Task* task = &ALLOCATE(context, Task)->Task; - TaskManager* taskManager = &createTaskManager(context)->TaskManager; - context->data[D_TaskManager]->TaskManager.taskManager = (union Data*)taskManager; goto createTask1(context, Gearef(context, LoopCounter), Gearef(context, TaskManager), @@ -202,7 +206,7 @@ struct Context* main_context = NEW(struct Context); initContext(main_context); - main_context->next = C_createData1; + main_context->next = C_initDataGears; struct Context* worker_contexts = NEWN(cpu_num, struct Context);
--- a/src/parallel_execution/rb_tree.c Mon Jan 09 05:58:46 2017 +0900 +++ b/src/parallel_execution/rb_tree.c Mon Jan 09 21:16:29 2017 +0900 @@ -2,6 +2,7 @@ #include "context.h" #include "origin_cs.h" +#include "stack.h" extern enum Relational compare(struct Node* node1, struct Node* node2); @@ -10,6 +11,7 @@ struct RedBlackTree* redBlackTree = &ALLOCATE(context, RedBlackTree)->RedBlackTree; tree->tree = (union Data*)redBlackTree; redBlackTree->root = NULL; + redBlackTree->nodeStack = &createSingleLinkedStack(context)->Stack; tree->put = C_putRedBlackTree; tree->get = C_getRedBlackTree; // tree->remove = C_removeRedBlackTree; @@ -35,7 +37,7 @@ printf("\n"); } -__code putRedBlackTree(struct Context* context, struct Stack* nodeStack, struct RedBlackTree* traverse, struct Node* node, struct Node* root, struct Node* newNode) { +__code putRedBlackTree(struct Context* context, struct RedBlackTree* traverse, struct Node* node, struct Node* root, struct Node* newNode) { printTree((union Data*)(traverse->root)); traverse->newNode = newNode; traverse->root = newNode; // this should done at stackClear @@ -52,10 +54,9 @@ __code putRedBlackTree_stub(struct Context* context) { struct Node* newNode = &ALLOCATE(context, Node)->Node; goto putRedBlackTree(context, - &context->data[D_Stack]->Stack, - &context->data[D_RedBlackTree]->RedBlackTree, - &context->data[D_Node]->Node, - context->data[D_RedBlackTree]->RedBlackTree.root, + &Gearef(context, Tree)->tree->RedBlackTree, + Gearef(context, Tree)->node, + Gearef(context, Tree)->tree->RedBlackTree.root, newNode ); } @@ -71,11 +72,11 @@ __code replaceNode_stub(struct Context* context) { goto replaceNode(context, - &context->data[D_RedBlackTree]->RedBlackTree, - context->data[D_RedBlackTree]->RedBlackTree.current, + &Gearef(context, Tree)->tree->RedBlackTree, + Gearef(context, Tree)->tree->RedBlackTree.current, //context->data[D_RedBlackTree]->RedBlackTree.newNode, - Gearef(context, RedBlackTree)->newNode, - &context->data[D_Stack]->Stack); + Gearef(context, Tree)->tree->RedBlackTree.newNode, + Gearef(context, Stack)); } __code replaceNode1(struct Context* context, struct RedBlackTree* traverse, struct Node* node, struct Node* oldNode, struct Node* newNode, struct Node* newnewNode, int result, enum Code next) { @@ -102,12 +103,12 @@ __code replaceNode1_stub(struct Context* context) { struct Node* newnewNode = &ALLOCATE(context, Node)->Node; goto replaceNode1(context, - &context->data[D_RedBlackTree]->RedBlackTree, - &context->data[D_Node]->Node, - context->data[D_RedBlackTree]->RedBlackTree.current, - context->data[D_RedBlackTree]->RedBlackTree.previous, + &Gearef(context, Tree)->tree->RedBlackTree, + Gearef(context, Tree)->node, + Gearef(context, Tree)->tree->RedBlackTree.current, + Gearef(context, Tree)->tree->RedBlackTree.previous, newnewNode, - context->data[D_RedBlackTree]->RedBlackTree.result, + Gearef(context, Tree)->tree->RedBlackTree.result, Gearef(context, Tree)->next); } @@ -122,10 +123,10 @@ __code insertNode_stub(struct Context* context) { goto insertNode(context, - &context->data[D_RedBlackTree]->RedBlackTree, - &context->data[D_Stack]->Stack, - &context->data[D_Node]->Node, - context->data[D_RedBlackTree]->RedBlackTree.newNode); + &Gearef(context, Tree)->tree->RedBlackTree, + Gearef(context, Stack), + Gearef(context, Tree)->node, + Gearef(context, Tree)->tree->RedBlackTree.newNode); } __code insertCase1(struct Context* context, struct RedBlackTree* traverse, struct Node *parent, struct Node *grandparent) { @@ -140,7 +141,7 @@ __code insertCase1_stub(struct Context* context) { goto insertCase1(context, - &context->data[D_RedBlackTree]->RedBlackTree, + &Gearef(context, Tree)->tree->RedBlackTree, &context->data[D_Stack]->Stack.data->Node, &context->data[D_Stack]->Stack.data1->Node); } @@ -153,7 +154,7 @@ } __code insertCase2_stub(struct Context* context) { - goto insertCase2(context, &context->data[D_RedBlackTree]->RedBlackTree); + goto insertCase2(context, &Gearef(context, Tree)->tree->RedBlackTree); } __code insertCase3(struct Context* context, struct RedBlackTree* traverse, struct Stack* nodeStack) { @@ -178,9 +179,8 @@ } __code insertCase3_stub(struct Context* context) { - goto insertCase3(context, &context->data[D_RedBlackTree]->RedBlackTree, - &context->data[D_Stack]->Stack - ); + goto insertCase3(context, &Gearef(context, Tree)->tree->RedBlackTree, + Gearef(context, Stack)); } __code insertCase4(struct Context* context, struct RedBlackTree* traverse, struct RotateTree* rotateTree) { @@ -212,7 +212,7 @@ } __code insertCase4_stub(struct Context* context) { - goto insertCase4(context, &context->data[D_RedBlackTree]->RedBlackTree, &context->data[D_RotateTree]->RotateTree); + goto insertCase4(context, &Gearef(context, Tree)->tree->RedBlackTree, Gearef(context, RotateTree)); } __code insertCase5(struct Context* context, struct RedBlackTree* traverse,struct Stack *nodeStack) { @@ -222,7 +222,7 @@ } __code insertCase5_stub(struct Context* context) { - goto insertCase5(context, &context->data[D_RedBlackTree]->RedBlackTree, &context->data[D_Stack]->Stack); + goto insertCase5(context, &Gearef(context, Tree)->tree->RedBlackTree, Gearef(context, Stack)); } __code insertCase51(struct Context* context, struct RedBlackTree* traverse, struct RotateTree *rotateTree, struct Node* current, struct Node* parent, struct Node* grandparent) { @@ -246,7 +246,12 @@ __code insertCase51_stub(struct Context* context) { struct Node* parent = &context->data[D_Stack]->Stack.data->Node; struct Node* grandparent = &context->data[D_Stack]->Stack.data1->Node; - goto insertCase51(context, &context->data[D_RedBlackTree]->RedBlackTree,&context->data[D_RotateTree]->RotateTree, context->data[D_RedBlackTree]->RedBlackTree.current, parent, grandparent); + goto insertCase51(context, + &Gearef(context, Tree)->tree->RedBlackTree, + Gearef(context, RotateTree), + Gearef(context, Tree)->tree->RedBlackTree.current, + parent, + grandparent); } __code rotateLeft(struct Context* context, struct RedBlackTree* traverse,struct Stack* nodeStack) { @@ -257,7 +262,7 @@ __code rotateLeft_stub(struct Context* context) { struct RedBlackTree* traverse = context->data[D_RotateTree]->RotateTree.traverse; - goto rotateLeft(context, traverse, &context->data[D_Stack]->Stack); + goto rotateLeft(context, traverse, Gearef(context, Stack)); } __code rotateLeft1(struct Context* context, struct Node* node, struct RedBlackTree* traverse, struct Node *parent,struct RotateTree *rotateTree) { @@ -286,7 +291,7 @@ traverse->current, traverse, parent, - &context->data[D_RotateTree]->RotateTree); + Gearef(context, RotateTree)); } __code rotateRight(struct Context* context, struct RedBlackTree* traverse,struct Stack *nodeStack) { @@ -297,7 +302,7 @@ __code rotateRight_stub(struct Context* context) { struct RedBlackTree* traverse = context->data[D_RotateTree]->RotateTree.traverse; - goto rotateLeft(context, traverse, &context->data[D_Stack]->Stack); + goto rotateLeft(context, traverse, Gearef(context, Stack)); } __code rotateRight1(struct Context* context, struct Node* node, struct RedBlackTree* traverse,struct Node *parent,struct RotateTree *rotateTree) { @@ -326,7 +331,7 @@ traverse->current, traverse, parent, - &context->data[D_RotateTree]->RotateTree); + Gearef(context, RotateTree)); } __code stackClear(struct Context* context, struct RedBlackTree* traverse,struct Stack *nodeStack, enum Code next) { @@ -337,7 +342,7 @@ } __code stackClear_stub(struct Context* context) { - goto stackClear(context, &context->data[D_RedBlackTree]->RedBlackTree,&context->data[D_Stack]->Stack, + goto stackClear(context, &Gearef(context, Tree)->tree->RedBlackTree, Gearef(context, Stack), Gearef(context, Tree)->next); } @@ -353,7 +358,7 @@ } __code getRedBlackTree_stub(struct Context* context) { - goto getRedBlackTree(context, &context->data[D_RedBlackTree]->RedBlackTree, Gearef(context, Tree)->next); + goto getRedBlackTree(context, &Gearef(context, Tree)->tree->RedBlackTree, Gearef(context, Tree)->next); } __code search(struct Context* context, struct RedBlackTree* traverse, struct Node* node, enum Code next) { @@ -376,7 +381,7 @@ } __code search_stub(struct Context* context) { - goto search(context, &context->data[D_RedBlackTree]->RedBlackTree, &context->data[D_Node]->Node, Gearef(context, Tree)->next); + goto search(context, &Gearef(context, Tree)->tree->RedBlackTree, Gearef(context, Node), Gearef(context, Tree)->next); } /* /\* __code delete(struct Context* context, struct Tree* tree) { *\/ */
--- a/src/parallel_execution/taskManager.c Mon Jan 09 05:58:46 2017 +0900 +++ b/src/parallel_execution/taskManager.c Mon Jan 09 21:16:29 2017 +0900 @@ -7,8 +7,8 @@ union Data* createTaskManager(struct Context* context) { struct TaskManager* taskManager = &ALLOCATE(context, TaskManager)->TaskManager; struct TaskManagerImpl* taskManagerImpl = &ALLOCATE(context, TaskManagerImpl)->TaskManagerImpl; - taskManagerImpl -> activeQueue = (struct Queue*)createSynchronizedQueue(context); - taskManagerImpl -> taskQueue = (struct Queue*)createSynchronizedQueue(context); + taskManagerImpl -> activeQueue = &createSynchronizedQueue(context)->Queue; + taskManagerImpl -> taskQueue = &createSynchronizedQueue(context)->Queue; taskManager->spawn = C_spawnTaskManager; taskManager->shutdown = C_shutdownTaskManager; // taskManager->deadLockDetected = C_deadLockDetected;