Mercurial > hg > Gears > GearsAgda
diff src/parallel_execution/main.c @ 95:3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 29 Jan 2016 05:36:52 +0900 |
parents | 851da1107223 |
children | 8987cf13d5bb |
line wrap: on
line diff
--- a/src/parallel_execution/main.c Tue Jan 26 08:50:30 2016 +0900 +++ b/src/parallel_execution/main.c Fri Jan 29 05:36:52 2016 +0900 @@ -1,5 +1,5 @@ #include <stdio.h> -#include <unistd.h> +#include <string.h> #include "context.h" #include "origin_cs.h" @@ -7,7 +7,9 @@ extern __code initContext(struct Context* context); extern void allocator(struct Context* context); -int length; +int cpu_num = 1; +int length = 1024; +int split; int* array_ptr; void print_queue(struct Element* element) { @@ -26,13 +28,19 @@ } __code code1(struct Context* context) { - puts("queue"); - print_queue(context->data[ActiveQueue]->queue.first); - puts("tree"); - print_tree(context->data[Tree]->tree.root); - puts("result"); + printf("cpus:\t\t%d\n", cpu_num); + printf("length:\t\t%d\n", length); + printf("length/task:\t%d\n", length/split); + /* puts("queue"); */ + /* print_queue(context->data[ActiveQueue]->queue.first); */ + /* puts("tree"); */ + /* print_tree(context->data[Tree]->tree.root); */ + /* puts("result"); */ - goto meta(context, CreateWorker); + context->next = CreateWorker; + stack_push(context->code_stack, &context->next); + + goto meta(context, StartTime); } __code code1_stub(struct Context* context) { @@ -43,12 +51,15 @@ int i = loopCounter->i; if (i < length) { - printf("%d\n", array->array[i]); - loopCounter->i++; + // printf("%d\n", array->array[i]); + if (array->array[i] == (i*2)) { + loopCounter->i++; + goto meta(context, Code2); + } else + puts("wrong result"); - goto meta(context, Code2); } - + goto meta(context, Exit); } @@ -59,7 +70,7 @@ __code createData1(struct Context* context, struct Allocate* allocate, struct LoopCounter* loopCounter) { int i = loopCounter->i; - if (i < length) { + if ((length/split*i) < length) { allocate->size = sizeof(struct Array); allocator(context); @@ -78,11 +89,12 @@ int i = loopCounter->i; array->index = i; + array->prefix = length/split; array->array = array_ptr; node->key = i; node->value = (union Data*)array; - + context->next = CreateTask1; goto meta(context, PutTree); @@ -186,30 +198,6 @@ goto putQueue4(context, &context->data[ActiveQueue]->queue, &context->data[context->dataNum]->element); } -__code getQueue(struct Context* context, struct Queue* queue, struct Node* node) { - if (queue->count == 0) - return; - - struct Element* first = queue->first; - if (__sync_bool_compare_and_swap(&queue->first, first, first->next)) { - queue->count--; - - context->next = GetQueue; - stack_push(context->code_stack, &context->next); - - context->next = first->task->code; - node->key = first->task->key; - - goto meta(context, Get); - } else { - goto meta(context, GetQueue); - } -} - -__code getQueue_stub(struct Context* context) { - goto getQueue(context, &context->data[ActiveQueue]->queue, &context->data[Node]->node); -} - __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { int i = loopCounter->i; @@ -244,16 +232,31 @@ } loopCounter->i = 0; - goto meta(context, Code2); + + context->next = Code2; + stack_push(context->code_stack, &context->next); + + goto meta(context, EndTime); } __code taskManager_stub(struct Context* context) { goto taskManager(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker); } +void init(int argc, char** argv) { + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-cpu") == 0) + cpu_num = (int)atoi(argv[i+1]); + else if (strcmp(argv[i], "-l") == 0) + length = (int)atoi(argv[i+1]); + else if (strcmp(argv[i], "-s") == 0) + split = (int)atoi(argv[i+1]); + } +} + + int main(int argc, char** argv) { - int cpu_num = (int)atoi(argv[1]); - length = (int)atoi(argv[2]); + init(argc, argv); array_ptr = (int*)malloc(sizeof(int)*length); @@ -262,7 +265,6 @@ struct Context* main_context = (struct Context*)malloc(sizeof(struct Context)); initContext(main_context); - //main_context->next = CreateWorker; main_context->next = CreateData1; struct Context* worker_contexts = (struct Context*)malloc(sizeof(struct Context)*cpu_num);