changeset 975:18650c9ff2b2

add new_wc
author ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
date Thu, 30 Sep 2021 00:25:36 +0900
parents c18acbe4f4da
children 76a86972c2eb
files src/parallel_execution/CMakeLists.txt src/parallel_execution/examples/new_wc/WordCount.h src/parallel_execution/examples/new_wc/WordCountImpl.cbc src/parallel_execution/examples/new_wc/WordCountImpl.h src/parallel_execution/examples/new_wc/WordPut.h src/parallel_execution/examples/new_wc/WordPutImpl.cbc src/parallel_execution/examples/new_wc/WordPutImpl.h src/parallel_execution/examples/new_wc/main.cbc src/parallel_execution/examples/new_wc/wcString.h src/parallel_execution/examples/new_wc/wcStringImpl.h src/parallel_execution/examples/rbtTest_sync/rbTree_sync_test.cbc
diffstat 11 files changed, 206 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Tue Sep 07 19:59:49 2021 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Thu Sep 30 00:25:36 2021 +0900
@@ -187,3 +187,17 @@
   SOURCES
       SingleLinkedQueue.cbc SynchronizedQueue.cbc AtomicReference.cbc examples/rbtTest_sync/rbTree_sync_test.cbc RedBlackTree.cbc SingleLinkedStack.cbc compare.c
 )
+
+GearsCommand(
+  TARGET
+     GHello
+  SOURCES
+     TaskManagerImpl.cbc CPUWorker.cbc SynchronizedQueue.cbc AtomicReference.cbc SingleLinkedStack.cbc examples/generics_hello/main.cbc examples/generics_hello/GHelloImpl.cbc examples/generics_hello/StringImpl.cbc
+)
+
+GearsCommand(
+  TARGET
+  newwc
+  SOURCES
+  TaskManagerImpl.cbc CPUWorker.cbc SynchronizedQueue.cbc AtomicReference.cbc SingleLinkedStack.cbc examples/new_wc/main.cbc examples/new_wc/WordPutImpl.cbc examples/new_wc/WordCountImpl.cbc
+)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/WordCount.h	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,7 @@
+typedef struct WordCount <> {
+    union Data* wordCount;
+    struct WordPut* wordPut;
+    union Data* data;
+    __code getWord(Impl* wordCount, Type* wordPut,  union Data* data,__code next(...));
+    __code next(...);
+} WordCount;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/WordCountImpl.cbc	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,27 @@
+#include "../../../context.h"
+#include <stdio.h>
+#interface "WordCount.h"
+#impl "WordCount.h" as "WordCountImpl.h" 
+#interface "WordPut.h"
+
+#interface "wcString.h"
+
+// ----
+// typedef struct WordCountImpl <> impl WordCount { 
+//   int wordNum;
+// } WcImpl;
+// ----
+
+WordCount* createWordCountImpl(struct Context* context) {
+    struct WordCount* wordCount  = new WordCount();
+    struct WordCountImpl* word_count_impl = new WordCountImpl();
+    wordCount->wordCount = (union Data*)word_count_impl;
+    word_count_impl->wordNum = 0;
+    wordCount->getWord = C_getWordWordCountImpl;
+    return wordCount;
+}
+__code getWord(struct WordCountImpl* wordCount, struct WordPut* wordPut, struct wcString* string, __code next(...)) {
+    printf("移動した\n");
+    //goto next(num);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/WordCountImpl.h	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,4 @@
+typedef struct WordCountImpl <> impl WordCount { 
+  int wordNum;
+  char* str;
+} WordCountImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/WordPut.h	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,6 @@
+typedef struct WordPut <> {
+    union Data* wordPut;
+    __code openFile(Impl* wordPut, __code next(...));
+    __code Put(Impl* wordPut, struct WordCount* wordcount, __code next(...));
+    __code next(...);
+} WordPut;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/WordPutImpl.cbc	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,57 @@
+#include "../../../context.h"
+#interface "WordPut.h"
+#impl "WordPut.h" as "WordCountImpl.h"
+#interface "WordCount.h"
+#include <stdio.h>
+
+#interface "wcString.h"
+
+// ----
+// typedef struct WordPutImpl <> impl WordPut {
+//   char* filename;
+// } WordPutImpl;
+// ----
+
+WordPut* createWordPutImpl(struct Context* context, char* fn) {
+    struct WordPut* wordPut  = new WordPut();
+    struct WordPutImpl* word_put_impl = new WordPutImpl();
+    wordPut->wordPut = (union Data*)word_put_impl;
+    word_put_impl->lineNum = 0;
+    word_put_impl->filename = fn;
+    wordPut->openFile = C_openFileWordPutImpl;
+    wordPut->Put = C_PutWordPutImpl;
+    word_put_impl->wordLen = 1000;
+    return wordPut;
+}
+__code openFile(struct WordPutImpl* wordPut, __code next(...)) {
+    printf("%s\n", wordPut->filename);
+    WordCount* wordCount = createWordCountImpl(context);
+    FILE* file = fopen(wordPut->filename, "r");
+    if (file == NULL){
+        printf("ファイルが開ませんでした\n");
+        exit(1);
+    } else {
+        printf("file open\n");
+    }
+
+    wordPut->file = (union Data*)file;
+    wordPut->lineNum = 4;
+    goto Put(wordCount);
+}
+
+__code Put(struct WordPutImpl* wordPut, struct WordCount* wordCount, __code next(...)) {
+    printf("Put\n");
+    char* str;    
+    int count = 0;
+    printf("%d\n", wordPut->lineNum);
+    while (fgets(str, wordPut->wordLen, wordPut->file) != NULL && count < wordPut->lineNum) {
+		if(count == wordPut->lineNum -1){
+            wcString* string = NEW(wcString);
+            string->str = str;
+            printf("%s", string->str);
+            goto wordCount->getWord(wordPut, string, Put);
+        }
+        count ++;
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/WordPutImpl.h	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,6 @@
+typedef struct WordPutImpl <> impl WordPut {
+  char* filename;
+  int lineNum;
+  int wordLen;
+  union Data* file;
+} WordPutImpl;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/main.cbc	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+#include "../../../context.h"
+#interface "TaskManager.h"
+#interface "WordPut.h"
+#interface "WordCount.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;
+char* filename;
+
+__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) {   
+  WordPut* wordPut = createWordPutImpl(context, filename);
+  //WordCount* wordCount = createWordCountImpl(context);
+  goto wordPut->openFile(code2); 
+}
+
+
+__code code2(struct TaskManager* taskManager) {
+    printf("code2 & end\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) {
+    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) {
+            filename = argv[i+1];
+        }
+    }
+}
+
+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/new_wc/wcString.h	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,3 @@
+typedef struct wcString <> {
+    char* str;
+} wcString;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/examples/new_wc/wcStringImpl.h	Thu Sep 30 00:25:36 2021 +0900
@@ -0,0 +1,3 @@
+typedef struct wcStringImpl <> impl wcString {
+  __code next(...);
+} wcStringImpl;
\ No newline at end of file
--- a/src/parallel_execution/examples/rbtTest_sync/rbTree_sync_test.cbc	Tue Sep 07 19:59:49 2021 +0900
+++ b/src/parallel_execution/examples/rbtTest_sync/rbTree_sync_test.cbc	Thu Sep 30 00:25:36 2021 +0900
@@ -21,10 +21,9 @@
   Node* node = new Node();
   node->value = (union Data*) createSynchronizedQueue(context);
   node->key = 4;
-  goto tree->put(node, exit_code);
+  //goto tree->put(node, exit_code);
 }
 
-
 int main(int argc, char const* argv[]) {
   printf("test_main\n");
   goto rbTreeTest1();