Mercurial > hg > Members > innparusu > Gears
changeset 92:851da1107223
implement twice
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Jan 2016 08:50:30 +0900 |
parents | 1e074c3878c7 |
children | 4dfa04d14221 3e28ee215c0e |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/context.c src/parallel_execution/context.h src/parallel_execution/main.c src/parallel_execution/rb_tree.c src/parallel_execution/swap.c src/parallel_execution/twice.c |
diffstat | 7 files changed, 63 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt Tue Jan 26 07:46:26 2016 +0900 +++ b/src/parallel_execution/CMakeLists.txt Tue Jan 26 08:50:30 2016 +0900 @@ -12,5 +12,6 @@ origin_cs.c allocate.c compare.c + twice.c )
--- a/src/parallel_execution/context.c Tue Jan 26 07:46:26 2016 +0900 +++ b/src/parallel_execution/context.c Tue Jan 26 08:50:30 2016 +0900 @@ -54,6 +54,7 @@ extern __code putQueue3_stub(struct Context*); extern __code putQueue4_stub(struct Context*); extern __code getQueue_stub(struct Context*); +extern __code twice_stub(struct Context*); extern __code exit_code(struct Context*); __code initContext(struct Context* context) { @@ -65,7 +66,7 @@ context->codeNum = Exit; context->code[Code1] = code1_stub; - //context->code[Code2] = code2_stub; + context->code[Code2] = code2_stub; /* context->code[Code3] = code3_stub; */ /* context->code[Code4] = code4; */ /* context->code[Code5] = code5; */ @@ -85,8 +86,8 @@ context->code[InsertCase4_2] = insert4_2_stub; context->code[InsertCase5] = insert5_stub; context->code[StackClear] = stackClear_stub; - /* context->code[Get] = get_stub; */ - /* context->code[Search] = search_stub; */ + context->code[Get] = get_stub; + context->code[Search] = search_stub; /* context->code[Delete] = delete_stub; */ /* context->code[Delete1] = delete1_stub; */ /* context->code[Delete2] = delete2_stub; */ @@ -112,6 +113,7 @@ context->code[PutQueue3] = putQueue3_stub; context->code[PutQueue4] = putQueue4_stub; context->code[GetQueue] = getQueue_stub; + context->code[Twice] = twice_stub; context->code[Exit] = exit_code; context->heap = context->heapStart;
--- a/src/parallel_execution/context.h Tue Jan 26 07:46:26 2016 +0900 +++ b/src/parallel_execution/context.h Tue Jan 26 08:50:30 2016 +0900 @@ -56,6 +56,7 @@ PutQueue3, PutQueue4, GetQueue, + Twice, Exit, }; @@ -84,6 +85,7 @@ void* heap; long heapLimit; pthread_t thread; + int thread_num; stack_ptr code_stack; stack_ptr node_stack; int dataNum;
--- a/src/parallel_execution/main.c Tue Jan 26 07:46:26 2016 +0900 +++ b/src/parallel_execution/main.c Tue Jan 26 08:50:30 2016 +0900 @@ -30,14 +30,32 @@ print_queue(context->data[ActiveQueue]->queue.first); puts("tree"); print_tree(context->data[Tree]->tree.root); + puts("result"); - goto meta(context, Exit); + goto meta(context, CreateWorker); } __code code1_stub(struct Context* context) { goto code1(context); } +__code code2(struct Context* context, struct Array* array, struct LoopCounter* loopCounter) { + int i = loopCounter->i; + + if (i < length) { + printf("%d\n", array->array[i]); + loopCounter->i++; + + goto meta(context, Code2); + } + + goto meta(context, Exit); +} + +__code code2_stub(struct Context* context) { + goto code2(context, &context->data[Node]->node.value->array, &context->data[LoopCounter]->loopCounter); +} + __code createData1(struct Context* context, struct Allocate* allocate, struct LoopCounter* loopCounter) { int i = loopCounter->i; @@ -48,6 +66,7 @@ goto meta(context, CreateData2); } + loopCounter->i = 0; goto meta(context, Code1); } @@ -90,7 +109,7 @@ __code createTask2(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Element* element) { int i = loopCounter->i; - task->code = Code1; + task->code = Twice; task->key = i; element->task = task; @@ -167,7 +186,7 @@ goto putQueue4(context, &context->data[ActiveQueue]->queue, &context->data[context->dataNum]->element); } -__code getQueue(struct Context* context, struct Queue* queue) { +__code getQueue(struct Context* context, struct Queue* queue, struct Node* node) { if (queue->count == 0) return; @@ -179,16 +198,16 @@ stack_push(context->code_stack, &context->next); context->next = first->task->code; - stack_push(context->code_stack, &context->next); + node->key = first->task->key; - goto meta(context, Search); + goto meta(context, Get); } else { goto meta(context, GetQueue); } } __code getQueue_stub(struct Context* context) { - goto getQueue(context, &context->data[ActiveQueue]->queue); + goto getQueue(context, &context->data[ActiveQueue]->queue, &context->data[Node]->node); } __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { @@ -200,6 +219,7 @@ worker_context->data[Tree] = context->data[Tree]; worker_context->data[ActiveQueue] = context->data[ActiveQueue]; pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); + worker_context->thread_num = i; loopCounter->i++; goto meta(context, CreateWorker); @@ -224,7 +244,7 @@ } loopCounter->i = 0; - goto meta(context, Exit); + goto meta(context, Code2); } __code taskManager_stub(struct Context* context) {
--- a/src/parallel_execution/rb_tree.c Tue Jan 26 07:46:26 2016 +0900 +++ b/src/parallel_execution/rb_tree.c Tue Jan 26 08:50:30 2016 +0900 @@ -303,20 +303,20 @@ } -/* /\* __code get(struct Context* context, struct Tree* tree) { *\/ */ -/* /\* if (tree->root) { *\/ */ -/* /\* tree->current = tree->root; *\/ */ +__code get(struct Context* context, struct Tree* tree, struct Traverse* traverse) { + if (tree->root) { + traverse->current = tree->root; -/* /\* goto meta(context, Search); *\/ */ -/* /\* } *\/ */ + goto meta(context, Search); + } -/* /\* stack_pop(context->code_stack, &context->next); *\/ */ -/* /\* goto meta(context, context->next); *\/ */ -/* /\* } *\/ */ + stack_pop(context->code_stack, &context->next); + goto meta(context, context->next); +} -/* /\* __code get_stub(struct Context* context) { *\/ */ -/* /\* goto get(context, &context->data[Tree]->tree); *\/ */ -/* /\* } *\/ */ +__code get_stub(struct Context* context) { + goto get(context, &context->data[Tree]->tree, &context->data[Traverse]->traverse); +} __code search(struct Context* context, struct Traverse* traverse, struct Node* node) { compare(context, traverse, traverse->current->key, node->key);
--- a/src/parallel_execution/swap.c Tue Jan 26 07:46:26 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -__code swap(struct Context* context, struct ) { -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/twice.c Tue Jan 26 08:50:30 2016 +0900 @@ -0,0 +1,17 @@ +#include <stdio.h> + +#include "context.h" +#include "origin_cs.h" + +__code twice(struct Context* context, int index, int* array) { + printf("No.%d %p\n", context->thread_num, context->thread); + array[index] = array[index]*2; + + stack_pop(context->code_stack, &context->next); + goto meta(context, context->next); +} + +__code twice_stub(struct Context* context) { + goto twice(context, context->data[Node]->node.value->array.index, context->data[Node]->node.value->array.array); +} +