changeset 954:faa9afc7dd07

add wc Example
author ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
date Sun, 28 Feb 2021 17:56:05 +0900
parents a86e0a2b7a30
children e7cff9d88e5f
files src/parallel_execution/examples/wc/Wc.h src/parallel_execution/examples/wc/WcImpl.cbc src/parallel_execution/examples/wc/WcImpl.h src/parallel_execution/examples/wc/WcResult.h src/parallel_execution/examples/wc/main.cbc src/parallel_execution/examples/wc/wcTarget.h
diffstat 6 files changed, 130 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/Wc.h	Sun Feb 28 17:56:05 2021 +0900
@@ -0,0 +1,8 @@
+typedef struct Wc <> {
+  union Data* wc;
+  char* filename;
+  WcResult* result; 
+  __code openFile(Impl* wc,char* filename, __code next(...));
+  __code countUp(Impl* wc,__code next(WcResult* result, ...));
+  __code next(...);
+} Wc;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/WcImpl.cbc	Sun Feb 28 17:56:05 2021 +0900
@@ -0,0 +1,34 @@
+#include "../../../context.h"
+#interface "Wc.h"
+
+// ----
+// typedef struct WcImpl <> impl Wc {
+//   FILE* file;
+//   char* Keyword; 
+//   int wordNum;
+// } WcImpl;
+// ----
+
+Wc* createWcImpl(struct Context* context) {
+    struct Wc* wc  = new Wc();
+    struct WcImpl* wc_impl = new WcImpl();
+    wc->wc = (union Data*)wc_impl;
+    wc->filename = NULL;
+    wc->result = NULL;
+    wc_impl->file = NULL;
+    wc_impl->Keyword = NULL;
+    wc_impl->wordNum = 0;
+    wc->openFile = C_openFileWcImpl;
+    wc->countUp = C_countUpWcImpl;
+    return wc;
+}
+__code openFile(struct WcImpl* wc,char* filename, __code next(...)) {
+   
+  goto next(...);
+}
+
+__code countUp(struct WcImpl* wc,__code next(WcResult* result, ...)) {
+
+    goto next(WcResult* result, ...);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/WcImpl.h	Sun Feb 28 17:56:05 2021 +0900
@@ -0,0 +1,5 @@
+typedef struct WcImpl <> impl Wc {
+  FILE* file;
+  char* Keyword; 
+  int wordNum;
+} WcImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/WcResult.h	Sun Feb 28 17:56:05 2021 +0900
@@ -0,0 +1,4 @@
+typedef struct WcResult <> {
+  int CountedNum;
+  char* Keyword;
+} WcResult;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/main.cbc	Sun Feb 28 17:56:05 2021 +0900
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../../../context.h"
+#interface "TaskManager.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;
+wcTarget target;
+
+__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) {
+   Wc* wc1 = createWcImpl(context);
+   goto wc1->openFile(target.);   
+}
+
+
+__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;
+        else if (strcmp(argv[i], "-f")) == 0) {
+            target.fileName = argv[i+1];
+            target.keyWord = argv[i+2];
+        }
+    }
+}
+
+int main(int argc, char** argv) {
+    init(argc, argv);
+    goto initDataGears();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/wc/wcTarget.h	Sun Feb 28 17:56:05 2021 +0900
@@ -0,0 +1,5 @@
+typedef struct wcTarget <> {
+  char* fileName;
+  char* keyWord;
+} wcTarget;
+