# HG changeset patch # User matac42 # Date 1623931280 -32400 # Node ID edbd4495f08ffca304b3166680cb09f8ae525d69 # Parent 89ea952f0f2b0823aee4d03d36c0784a920663ac add helloWorld diff -r 89ea952f0f2b -r edbd4495f08f src/parallel_execution/CMakeLists.txt --- a/src/parallel_execution/CMakeLists.txt Tue Apr 13 18:54:35 2021 +0900 +++ b/src/parallel_execution/CMakeLists.txt Thu Jun 17 21:01:20 2021 +0900 @@ -173,3 +173,10 @@ TaskManagerImpl.cbc CPUWorker.cbc SynchronizedQueue.cbc AtomicReference.cbc SingleLinkedStack.cbc examples/wc/main.cbc examples/wc/WcImpl.cbc ) +GearsCommand( + TARGET + hello_world + SOURCES + TaskManagerImpl.cbc CPUWorker.cbc SynchronizedQueue.cbc AtomicReference.cbc SingleLinkedStack.cbc examples/helloWorld/main.cbc examples/helloWorld/HelloImpl.cbc +) + diff -r 89ea952f0f2b -r edbd4495f08f src/parallel_execution/examples/helloWorld/Hello.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/helloWorld/Hello.h Thu Jun 17 21:01:20 2021 +0900 @@ -0,0 +1,7 @@ +typedef struct Hello <> { + union Data* hello; + char* string; + __code h(Impl* hello, __code next(...)); + __code w(Impl* hello, __code next(...)); + __code next(...); +} Hello; diff -r 89ea952f0f2b -r edbd4495f08f src/parallel_execution/examples/helloWorld/HelloImpl.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/helloWorld/HelloImpl.cbc Thu Jun 17 21:01:20 2021 +0900 @@ -0,0 +1,34 @@ +#include "../../../context.h" +#include +#impl "Hello.h" as "HelloImpl.h" +#interface "Hello.h" + +// ---- +// typedef struct HelloImpl <> impl Hello { +// char* hString; +// char* wString; +// } HelloImpl; +// ---- + +Hello* createHelloImpl(struct Context* context) { + struct Hello* hello = new Hello(); + struct HelloImpl* hello_impl = new HelloImpl(); + hello->hello = (union Data*)hello_impl; + hello->string = NULL; + hello_impl->hString = NULL; + hello_impl->wString = NULL; + hello->h = C_hHelloImpl; + hello->w = C_wHelloImpl; + return hello; +} +__code h(struct HelloImpl* hello, __code next(...)) { + hello->string = "Hello, "; + printf("%s", hello->string); + goto w(hello, next); +} + +__code w(struct HelloImpl* hello, __code next(...)) { + // printf("%s", hello_impl->wString); + goto next(...); +} + diff -r 89ea952f0f2b -r edbd4495f08f src/parallel_execution/examples/helloWorld/HelloImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/helloWorld/HelloImpl.h Thu Jun 17 21:01:20 2021 +0900 @@ -0,0 +1,4 @@ +typedef struct HelloImpl <> impl Hello { + char* hString; + char* wString; +} HelloImpl; diff -r 89ea952f0f2b -r edbd4495f08f src/parallel_execution/examples/helloWorld/main.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/examples/helloWorld/main.cbc Thu Jun 17 21:01:20 2021 +0900 @@ -0,0 +1,72 @@ +#include +#include +#include +#include + + +#include "../../../context.h" +#interface "TaskManager.h" +#interface "Hello.h" + +int cpu_num = 1; +int length = 102400; +int split = 8; +int* array_ptr; +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 LoopCounter* loopCounter) { + printf("cpus:\t\t%d\n", cpu_num); + printf("gpus:\t\t%d\n", gpu_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 createTask1(); +} + + +__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { + Hello* hello = createHelloImpl(context); + goto hello->h(code2); +} + + +__code code2(struct TaskManager* taskManager) { + goto taskManager->shutdown(exit_code); +} + +__code code2_stub(struct Context* context) { + goto code2(context, &Gearef(context, TaskManager)->taskManager->TaskManager); +} + +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]); + else if (strcmp(argv[i], "-cuda") == 0) { + gpu_num = 1; + CPU_CUDA = 0; + } + } +} + +int main(int argc, char** argv) { + init(argc, argv); + goto initDataGears(); +}