diff src/parallel_execution/examples/DebughelloWorld/main.cbc @ 1015:e6778c866876

add DebugWorker and DebugTaskManager
author Takato Matsuoka <t.matsuoka@cr.ie.u-ryukyu.ac.jp>
date Tue, 18 Jan 2022 19:54:28 +0900
parents
children 3e8d89f271e2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/DebughelloWorld/main.cbc	Tue Jan 18 19:54:28 2022 +0900
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+#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) {
+    printf("[Debug log] initDataGears in main\n");
+    // loopCounter->tree = createRedBlackTree(context);
+    loopCounter->i = 0;
+    taskManager->taskManager = (union Data*)createDebugTaskManagerImpl(context, cpu_num, gpu_num, 0);
+    goto code1();
+}
+
+__code code1(struct LoopCounter* loopCounter) {
+    printf("[Debug log] code1 in main\n");
+    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);
+    goto createTask1();
+}
+
+
+__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
+    printf("[Debug log] createTask1 in main\n");
+    Hello* hello = createHelloImpl(context);
+    goto hello->h(code2); 
+}
+
+
+__code code2(struct TaskManager* taskManager) {
+    printf("[Debug log] code2 in main\n");
+    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) {
+    printf("[Debug log] init in main\n");
+    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) {
+    printf("[Debug log] main in main\n");
+    init(argc, argv);
+    goto initDataGears();
+}