changeset 131:a4507906938c

Fix compile error but not work
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 25 Oct 2016 00:49:28 +0900
parents 2bb5e4f0fd35
children 7c309e1aea73
files src/parallel_execution/CMakeLists.txt src/parallel_execution/allocate.c src/parallel_execution/compare.c src/parallel_execution/context.c src/parallel_execution/context.h src/parallel_execution/rb_tree.c src/parallel_execution/stack.c src/parallel_execution/twice.c src/parallel_execution/worker.c
diffstat 9 files changed, 67 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Tue Oct 25 00:49:28 2016 +0900
@@ -3,7 +3,7 @@
 # -DUSE_CUDA
 add_definitions("-Wall -g -O")
 
-set(CMAKE_C_COMPILER /Users/one/src/cbclang/Debug+Asserts/bin/clang)
+set(CMAKE_C_COMPILER $ENV{CBC_COMPILER})
 
 add_executable(twice
                main.c
--- a/src/parallel_execution/allocate.c	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/allocate.c	Tue Oct 25 00:49:28 2016 +0900
@@ -6,12 +6,12 @@
     return context->data[context->dataNum];
 }
 
-__code allocator(struct Context* context, struct Allocate* allocate) {
+__code allocatorCS(struct Context* context, struct Allocate* allocate) {
     context->data[++context->dataNum] = context->heap;
     context->heap += allocate->size;
     goto meta(context, allocate->next);
 }
 
 __code allocator_stub(struct Context* context) {
-    goto allocator(context, &context->[Allocate]->allocate);
+    goto allocatorCS(context, &context->data[Allocate]->allocate);
 }
--- a/src/parallel_execution/compare.c	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/compare.c	Tue Oct 25 00:49:28 2016 +0900
@@ -1,11 +1,13 @@
 #include "context.h"
 
-void compare(struct Context* context, struct Traverse* traverse, int key1, int key2) {
+enum Relational compare(struct Node* node1, struct Node* node2) {
+    int key1 = node1->key;
+    int key2 = node2->key;
     if (key1 == key2) {
-        traverse->result = EQ;
+        return EQ;
     } else if (key1 < key2) {
-        traverse->result = GT;
+        return GT;
     } else {
-        traverse->result = LT;
+        return LT;
     }
 }
--- a/src/parallel_execution/context.c	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/context.c	Tue Oct 25 00:49:28 2016 +0900
@@ -60,6 +60,8 @@
 extern __code putQueue3_stub(struct Context*);
 extern __code putQueue4_stub(struct Context*);
 extern __code getQueue_stub(struct Context*);
+extern __code pushSingleLinkedStack_stub(struct Context*);
+extern __code popSingleLinkedStack_stub(struct Context*);
 extern __code spawnTask_stub(struct Context*);
 extern __code twice_stub(struct Context*);
 extern __code start_time_stub(struct Context*);
@@ -129,6 +131,8 @@
     context->code[PutQueue3]     = putQueue3_stub;
     context->code[PutQueue4]     = putQueue4_stub;
     context->code[GetQueue]      = getQueue_stub;
+    context->code[PushSingleLinkedStack] = pushSingleLinkedStack_stub;
+    context->code[PopSingleLinkedStack] = popSingleLinkedStack_stub;
     context->code[SpawnTask]     = spawnTask_stub;
     context->code[Twice]         = twice_stub;
     context->code[StartTime]     = start_time_stub;
@@ -142,11 +146,15 @@
     struct Allocate* allocate = ALLOC_DATA(context, Allocate);
     allocate->size = 0;
 
-    struct SingleLinkedStack* stack = ALLOC_DATA(context, SignleLinkedStack);
-    stack->top = NULL;
-    stack->i.push = _;
-    stack->i.pop = _;
-    stack->i.isEmpty = _;
+    
+    struct SingleLinkedStack* singleLinkedStack = ALLOC_DATA(context, SingleLinkedStack);
+    singleLinkedStack->top = NULL;
+    singleLinkedStack->i.push = PushSingleLinkedStack;
+    singleLinkedStack->i.pop = PopSingleLinkedStack;
+    singleLinkedStack->i.isEmpty = NULL;
+    singleLinkedStack->i.stack = (union StackSelf*)singleLinkedStack;
+
+    context->data[Stack] = (union Data*)&singleLinkedStack->i;
 
     struct Tree* tree = ALLOC_DATA(context, Tree);
     tree->root = 0;
--- a/src/parallel_execution/context.h	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/context.h	Tue Oct 25 00:49:28 2016 +0900
@@ -71,6 +71,8 @@
     PutQueue3,
     PutQueue4,
     GetQueue,
+    PushSingleLinkedStack,
+    PopSingleLinkedStack,
     SpawnTask,
     Twice,
     StartTime,
@@ -87,6 +89,8 @@
 enum DataType {
     Worker,
     Allocate,
+    SingleLinkedStack,
+    Stack,
     Tree,
     Traverse,
     Node,
@@ -95,7 +99,7 @@
     Element,
     ActiveQueue,
     WaitQueue,
-    Queue,
+    Queue
 };
 
 struct Context {
@@ -107,8 +111,6 @@
     long heapLimit;
     pthread_t thread;
     int thread_num;
-    stack_ptr code_stack;
-    stack_ptr node_stack;
     int dataNum;
     union Data **data;
 };
@@ -168,7 +170,7 @@
         enum Code pop;
         enum Code isEmpty;
         enum Code next;
-    };
+    } stack;
     union StackSelf {
         struct SingleLinkedStack {
             struct Stack i;
@@ -178,7 +180,7 @@
             int size;
             int limit;
             struct Element* array;
-        }
+        } arrayStack;
     };
     struct Element {
         union Data* data;
--- a/src/parallel_execution/rb_tree.c	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/rb_tree.c	Tue Oct 25 00:49:28 2016 +0900
@@ -3,8 +3,8 @@
 #include "context.h"
 #include "origin_cs.h"
 
-extern void allocator(struct Context* context);
-extern void compare(struct Context* context, struct Traverse* traverse, int key1, int key2);
+extern union Data* allocator(struct Context* context);
+extern enum Relational compare(struct Node* node1, struct Node* node2);
 
 void printTree1(union Data* data) {
     struct Node* node = (struct Node*)data;
@@ -31,7 +31,8 @@
     if (root) {
         traverse->current = root;
         // traverse->result=compare(...)
-        traverse->result = traverse->compare(traverse->current, node);
+        // traverse->result = traverse->compare(traverse->current, node);
+        traverse->result = compare(traverse->current, node);
         nodeStack->stack = traverse->nodeStack;
         nodeStack->data = (union Data*)newNode;
         nodeStack->next = Replace1;
@@ -92,7 +93,8 @@
     }
     traverse->newNode = newnewNode;
     if (traverse->current) {
-        compare(context, traverse, traverse->current->key, node->key);
+        // compare(context, traverse, traverse->current->key, node->key);
+        traverse->result = compare(traverse->current, node);
         goto meta(context, Replace);
     }
     
@@ -334,7 +336,7 @@
                      parent);
 }
 
-__code stackClear(struct Context* context, stack_ptr node_stack, struct Traverse* traverse) {
+__code stackClear(struct Context* context, struct Traverse* traverse) {
     traverse->current = 0;
     traverse->nodeStack = NULL;
 
@@ -342,7 +344,7 @@
 }
 
 __code stackClear_stub(struct Context* context) {
-    goto stackClear(context, context->node_stack, &context->data[Traverse]->traverse);
+    goto stackClear(context, &context->data[Traverse]->traverse);
 }
     
 
@@ -353,7 +355,7 @@
         goto meta(context, Search);
     }
 
-    goto meta(context, context->next);
+    goto meta(context, traverse->next);
 }
 
 __code get_stub(struct Context* context) {
@@ -361,12 +363,12 @@
 }
 
 __code search(struct Context* context, struct Traverse* traverse, struct Node* node) {
-    compare(context, traverse, traverse->current->key, node->key);
-    
+    // compare(context, traverse, traverse->current->key, node->key);
+    traverse->result = compare(traverse->current, node);
     if (traverse->result == EQ) {
         *node = *traverse->current;
         
-        goto meta(context, context->next);
+        goto meta(context, traverse->next);
     } else if (traverse->result == GT) {
         traverse->current = traverse->current->right;
     } else {
@@ -376,7 +378,7 @@
     if (traverse->current)
         goto meta(context, Search);
 
-    goto meta(context, context->next);
+    goto meta(context, traverse->next);
 }
 
 __code search_stub(struct Context* context) {
--- a/src/parallel_execution/stack.c	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/stack.c	Tue Oct 25 00:49:28 2016 +0900
@@ -1,31 +1,44 @@
 #include "stack.h"
+#include "context.h"
+#include "origin_cs.h"
+extern union Data* allocator(struct Context* context);
 
-__code createSingleLinkedStack(enum Code next) {
+__code createSingleLinkedStack(struct Context* context, enum Code next) {
+    /*
     struct SingleLinkedStack* stack = allocate(context, SignleLinkedStack);
     stack->top = NULL;
     stack->i.push = PushSingleLinkedStack;
     stack->i.pop = PopsingleLinkedStack;
     stack->i.isEmpty = _;
+    */
     goto meta(context, next);
 }
 
-__code pushSingleLinkedStack(struct Context* context, struct SingleLinekedStack* stack, struct Element* element, union Data* data, enum Code next) {
+__code pushSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) {
     element->next = stack->top;
     element->data = data;
     stack->top = element;
     goto meta(context, next);
 }
 
-__code popSingleLinkedStack(struct Context* context, struct SingleLinekedStack* stack, enum Code next) {
+__code pushSingleLinkedStack_stub(struct Context* context) {
+    struct Allocate* allocate = &context->data[Allocate]->allocate;
+    allocate->size = sizeof(struct Element);
+    struct Element* element = &(allocator(context)->element);
+    goto pushSingleLinkedStack(context,
+                               &context->data[Stack]->stack.stack,
+                               element,
+                               context->data[Stack]->stack.data,
+                               context->data[Stack]->stack.next);
+}
+
+__code popSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, enum Code next) {
     stack->top = stack->top->next;
     goto meta(context, next);
 }
 
-__code pushSingleLinkedStack_stub(struct Context* context) {
-    stuct Element* element = allocate(struct Element);
-    goto pushSingleLinkedStack(context,
-                               &context->data[Stack]->stack,
-                               element,
-                               context->data[Stack]->data,
-                               context->data[Stack]->next);
+__code popSingleLinkedStack_stub(struct Context* context) {
+    goto popSingleLinkedStack(context,
+                               &context->data[Stack]->stack.stack,
+                               context->data[Stack]->stack.next);
 }
--- a/src/parallel_execution/twice.c	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/twice.c	Tue Oct 25 00:49:28 2016 +0900
@@ -15,7 +15,7 @@
 
     loopCounter->i = 0;
 
-    stack_pop(context->code_stack, &context->next);
+    //stack_pop(context->code_stack, &context->next);
     goto meta(context, context->next);
 }
 
--- a/src/parallel_execution/worker.c	Mon Oct 10 20:19:26 2016 +0900
+++ b/src/parallel_execution/worker.c	Tue Oct 25 00:49:28 2016 +0900
@@ -12,13 +12,10 @@
         queue->count--;
 
         context->next = GetQueue;
-        stack_push(context->code_stack, &context->next);
-
-        context->next = ((struct Task *)(first->data))->code;
         node->key = ((struct Task *)(first->data))->key;
 
         struct Traverse *t = &context->data[Traverse]->traverse;
-        t->next = GetQueue;
+        t->next = ((struct Task *)(first->data))->code;
         goto meta(context, Get);
     } else {
         goto meta(context, GetQueue);