Mercurial > hg > Gears > GearsAgda
changeset 346:9f8a87389b68
Add Mult.cbc
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 30 May 2017 03:38:38 +0900 |
parents | 2da00c034fbc |
children | 9578c38c10d1 |
files | .hgignore src/parallel_execution/CodeGear.cbc src/parallel_execution/Worker.cbc src/parallel_execution/examples/Add.cbc src/parallel_execution/examples/Mult.cbc src/parallel_execution/examples/calc.cbc |
diffstat | 6 files changed, 80 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon May 29 20:55:07 2017 +0900 +++ b/.hgignore Tue May 30 03:38:38 2017 +0900 @@ -1,5 +1,5 @@ syntax: glob - +.DS_Store *.swp *.o *.agdai
--- a/src/parallel_execution/CodeGear.cbc Mon May 29 20:55:07 2017 +0900 +++ b/src/parallel_execution/CodeGear.cbc Tue May 30 03:38:38 2017 +0900 @@ -2,6 +2,7 @@ union Data* codeGear; enum Code code; __code code(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)); + __code setInfo(struct Context* codeGear, union Data** dataGears, __code next(...)); union Data* dataGears[10]; __code next(...); } CodeGear;
--- a/src/parallel_execution/Worker.cbc Mon May 29 20:55:07 2017 +0900 +++ b/src/parallel_execution/Worker.cbc Tue May 30 03:38:38 2017 +0900 @@ -1,7 +1,7 @@ -typedef struct Worker<:Impl>{ +typedef struct Worker<Impl>{ union Data* worker; __code taskReseive(struct Worker* worker,struct Queue* queue); __code shutdown(Impl* worker); - __codenext(...); + __code next(...); struct Queue* queue; } Worker;
--- a/src/parallel_execution/examples/Add.cbc Mon May 29 20:55:07 2017 +0900 +++ b/src/parallel_execution/examples/Add.cbc Tue May 30 03:38:38 2017 +0900 @@ -1,5 +1,5 @@ #include "../../context.h" -CodeGear* createAddCodeGear(Context* context) { +CodeGear* createAddCodeGear(struct Context* context) { struct CodeGear* codeGear = new CodeGear(); struct context* addContext = NEW(struct Context); codeGear->codeGear = (union Data*)addContext; @@ -9,7 +9,7 @@ return codeGear; } -CodeGear* setAddCodeGearInfo(Context* codeGear, Data** dataGears) { +__code setAddCodeGearInfo(struct Context* codeGear, union Data** dataGears, __code next(...)) { codeGear->next = C_add; codeGear->idgCount = 2; codeGear->idg = codeGear->datanum; @@ -22,7 +22,7 @@ goto meta(context, C_setWaitTask) } -__code setWaitTask(Context* codeGear, Queue* Queue, LoopCounter* loopCounter, Data** dataGears, __code next(...)) { +__code setWaitTask(struct Context* codeGear, struct Queue* Queue, struct LoopCounter* loopCounter, union Data** dataGears, __code next(...)) { if(loopCounter->i < codeGear->idgCount) { queue->queue = (Data *)GET_WAIT_LIST(data); queue->data = codeGears[loopCoutner->i]; @@ -30,7 +30,7 @@ loopCounter->i++; goto meta(context, queue->queue->Queue.put); } - taskManager->context = task; + taskManager->context = codeGear; taskManager->next = next; goto meta(context, taskManager->spawn); } @@ -39,3 +39,18 @@ Context* codeGear = GearImpl(context, CodeGear, codeGear) goto setWaitTask(context, codeGear, Gearef(context, Queue), Gearef(codeGear, LoopCounter), Gearef(context, CodeGear)->dataGears, Gearef(context, CodeGear)->next); } + +__code add(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)) { + output->value = input1->value + input2->value; + printf("%d + %d = %d\n", input1->value, input2->value, output->value); + goto meta(context, next); +} + +__code add_stub(struct Context* context) { + goto add(context, + &context->data[context->idg]->Integer, + &context->data[context->idg + 1]->Integer, + &context->data[context->odg]->Integer, + context->next); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/Mult.cbc Tue May 30 03:38:38 2017 +0900 @@ -0,0 +1,44 @@ +#include "../../context.h" +CodeGear* createMultCodeGear(struct Context* context) { + struct CodeGear* codeGear = new CodeGear(); + struct context* multContext = NEW(struct Context); + codeGear->codeGear = (union Data*)multContext; + initContext(multContext); + codeGear->code = C_mult; + codeGear->setInfo = C_setMultCodeGearInfo; + return codeGear; +} + +__code setMultCodeGearInfo(struct Context* codeGear, union Data** dataGears, __code next(...)) { + codeGear->next = C_mult; + codeGear->idgCount = 2; + codeGear->idg = codeGear->datanum; + codeGear->data[codeGear->idg] = dataGears[0]; + codeGear->data[codeGear->idg+1] = dataGears[1]; + codeGear->maxIdg = codeGear->idg + 2; + codeGear->odg = codeGear->maxIdg; + codeGear->data[codeGear->odg] = dataGears[2]; + task->maxOdg = task->odg + 1; + goto meta(context, C_setWaitTask) +} + +__code setWaitTask_stub(struct Context* context) { + Context* codeGear = GearImpl(context, CodeGear, codeGear) + goto setWaitTask(context, codeGear, Gearef(context, Queue), Gearef(codeGear, LoopCounter), Gearef(context, CodeGear)->dataGears, Gearef(context, CodeGear)->next); +} + +__code mult(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)) { + output->value = input1->value * input2->value; + printf("%d + %d = %d\n", input1->value, input2->value, output->value); + goto meta(context, next); +} + +__code mult_stub(struct Context* context) { + goto mult(context, + &context->data[context->idg]->Integer, + &context->data[context->idg + 1]->Integer, + &context->data[context->odg]->Integer, + context->next); + +} +
--- a/src/parallel_execution/examples/calc.cbc Mon May 29 20:55:07 2017 +0900 +++ b/src/parallel_execution/examples/calc.cbc Tue May 30 03:38:38 2017 +0900 @@ -95,8 +95,7 @@ if (i < length) { loopCounter->i++; - taskManager->next = C_createTask2; - goto meta(context, taskManager->taskManager->TaskManager.createTask); + goto meta(context, C_createTask2); } loopCounter->i = 0; @@ -104,11 +103,17 @@ goto meta(context, taskManager->taskManager->TaskManager.shutdown); } -__code createTask2(LoopCounter* loopCounter, TaskManager* taskManager, struct Context *task, Integer *integer1, Integer *integer2, Integer *integer3) { +__code createTask2(LoopCounter* loopCounter, TaskManager* taskManager, Integer *integer1, Integer *integer2, Integer *integer3) { int i = loopCounter->i; - integer2->value = i; - par goto mult(integer1, integer2, integer3, _exit); - goto createTask3; + integer1->value = i; + integer2->value = i+1; + + codeGear->codeGear= createMultCodeGear(context); + codeGear->codeGear[0] = (union Data*)integer1; + codeGear->codeGear[1] = (union Data*)integer2; + codeGear->codeGear[2] = (union Data*)integer3; + codeGear->next = C_createTask1; + goto meta(context, codeGear->codeGear->CodeGear.setInfo); } __code createTask2_stub(struct Context* context) { @@ -124,12 +129,7 @@ integer3); } -__code createTask3(struct TaskManager* taskManager) { - taskManager->next = C_createTask4; - goto meta(context, taskManager->taskManager->TaskManager.spawn); -} - -__code createTask4(LoopCounter* loopCounter, TaskManager* taskManager, struct Context* task, Integer *integer1, Integer *integer2, Integer *integer3) { +__code createTask3(LoopCounter* loopCounter, TaskManager* taskManager, Integer *integer1, Integer *integer2, Integer *integer3) { int i = loopCounter->i; integer1->value = i; integer2->value = i+1; @@ -139,17 +139,15 @@ codeGear->codeGear[1] = (union Data*)integer2; codeGear->codeGear[2] = (union Data*)integer3; codeGear->next = C_createTask1; - codeGear->taskManager = taskManager; goto meta(context, codeGear->codeGear->CodeGear.setInfo); } -__code createTask4_stub(struct Context* context) { +__code createTask3_stub(struct Context* context) { Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; goto createTask5(context, Gearef(context, LoopCounter), Gearef(context, TaskManager), - Gearef(context, TaskManager)->context, integer1, integer2, &Gearef(context, TaskManager)->data->Integer); @@ -179,20 +177,6 @@ goto start_code(main_context); } -__code add(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)) { - output->value = input1->value + input2->value; - printf("%d + %d = %d\n", input1->value, input2->value, output->value); - goto meta(context, context->next); -} - -__code add_stub(struct Context* context) { - goto add(context, - &context->data[context->idg]->Integer, - &context->data[context->idg + 1]->Integer, - &context->data[context->odg]->Integer); - -} - __code mult(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)) { output->value = input1->value * input2->value; printf("%d * %d = %d\n", input1->value, input2->value, output->value);