Mercurial > hg > Gears > Gears
changeset 1025:9cfc2a9aeedc
merge
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 31 Mar 2022 13:50:33 +0900 |
parents | d7d76f4a06c7 |
children | a48a77a88b4e |
files | src/parallel_execution/examples/distributedCountUp/CNumber.h src/parallel_execution/examples/distributedCountUp/CountUp.h src/parallel_execution/examples/distributedCountUp/CountUpImpl.cbc src/parallel_execution/examples/distributedCountUp/CountUpImpl.h src/parallel_execution/examples/distributedCountUp/echoNum.cbc src/parallel_execution/examples/distributedCountUp/main.cbc |
diffstat | 6 files changed, 151 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/distributedCountUp/CNumber.h Thu Mar 31 13:50:33 2022 +0900 @@ -0,0 +1,3 @@ +typedef struct CNumber <> { + int num; +} CNumber; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/distributedCountUp/CountUp.h Thu Mar 31 13:50:33 2022 +0900 @@ -0,0 +1,8 @@ +typedef struct CountUp <> { + union Data* countUp; + union Data* num; + int line; + __code eNum(Impl* countUp, union Data* num, __code next(...)); + __code test(Impl* countUp, __code next(...)); + __code next(...); +} CountUp; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/distributedCountUp/CountUpImpl.cbc Thu Mar 31 13:50:33 2022 +0900 @@ -0,0 +1,48 @@ +#include "../../../context.h" +#impl "CountUp.h" as "CountUpImpl.h" +#interface "Worker.h" +#interface "TaskManager.h" +#interface "CNumber.h" + +// ---- +// typedef struct CountUpImpl <> impl CountUp { +// } CountUpImpl; +// ---- + + +CountUp* createCountUpImpl(struct Context* context) { + struct CountUp* countUp = new CountUp(); + struct CountUpImpl* count_up_impl = new CountUpImpl(); + countUp->countUp = (union Data*)count_up_impl; + countUp->line = 0; + countUp->num = 0; + countUp->eNum = C_eNumCountUpImpl; + countUp->test = C_testCountUpImpl; + return countUp; +} + +__code eNum(struct CountUpImpl* countUp, CNumber* num, __code next(...)) { + if(num->num < 100){ + printf("%d\n", num->num); + CNumber* nNum = NEW(CNumber); + nNum->num = num->num + 1; + printf("next is %d\n", nNum->num); + Gearef(context, CountUp)->num = nNum; + goto eNum(nNum); + } else { + + } +} + +__code eNumCountUpImpl_stub(struct Context* context) { + CountUpImpl* countUp = (CountUpImpl*)GearImpl(context, CountUp, countUp); + CNumber* num = Gearef(context, CNumber)->num; + enum Code next = Gearef(context, CountUp)->next; + goto eNumCountUpImpl(context, countUp, num, next); +} + +__code test(struct CountUpImpl* countUp, __code next(...)){ + printf("tsts\n"); + goto next(...); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/distributedCountUp/CountUpImpl.h Thu Mar 31 13:50:33 2022 +0900 @@ -0,0 +1,2 @@ +typedef struct CountUpImpl <> impl CountUp { +} CountUpImpl; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/distributedCountUp/echoNum.cbc Thu Mar 31 13:50:33 2022 +0900 @@ -0,0 +1,11 @@ +#include "../../../context.h" +#include <stdio.h> +#interface "CountUp.h" +#interface "CNumber.h" + +__code echoNum(struct CountUp* countUp, struct CNumber* cNum, __code next(...), struct LoopCounter* loopCounter) { + printf("echoNum\n"); + goto next(...); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/distributedCountUp/main.cbc Thu Mar 31 13:50:33 2022 +0900 @@ -0,0 +1,79 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <assert.h> + +#include "../../../context.h" +#interface "TaskManager.h" +#interface "CountUp.h" +#interface "CNumber.h" + + +int cpu_num = 2; +int length = 100; +int buffer_size = 10; +int gpu_num = 0; +int CPU_ANY = -1; +int CPU_CUDA = -1; + +__code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { + // loopCounter->tree = createRedBlackTree(context); + loopCounter->i = 0; + taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0); + goto code1(); +} + +__code code1(struct Timer* timer) { + printf("cpus:\t\t%d\n", cpu_num); + printf("gpus:\t\t%d\n", gpu_num); + printf("length:\t\t%d\n", length); + goto createTask1(); +} + +__code code2(struct TaskManager* taskManager) { + printf("code2\n"); + goto taskManager->shutdown(exit_code); +} + +__code code2_stub(struct Context* context) { + goto code2(context, &Gearef(context, TaskManager)->taskManager->TaskManager); +} + +__code createTask1(struct TaskManager* taskManager) { + struct CountUp* countUp = createCountUpImpl(context); + struct CountUp* countUp2 = createCountUpImpl(context); + printf("createTask1\n"); + CNumber* cNum = new CNumber(); + cNum->num = 0; + //per gato echoNum(countUp, cNum, __exit); //TaskのCGをファイル単位にした場合。タスク実行がされない。 + //per gato echoNum(countUp2, cNum, __exit); + par goto countUp->eNum(cNum, test); //__exitを使いたいのだが.. + par goto countUp2->eNum(cNum, test); //par gotoのinputDGにシングルトンを指定するとダメ? + //workerがexit_codeに飛ぶとダメ? + goto code2(); +} + +__code test(struct TaskManager* taskManager){ + goto exit_code(); +} + +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], "-bufferSize") == 0) + buffer_size = (int)atoi(argv[i+1]); + else if (strcmp(argv[i], "-cuda") == 0) { + gpu_num = 1; + CPU_CUDA = 0; + } + } +} + +int main(int argc, char** argv) { + init(argc, argv); + goto initDataGears(); +}