changeset 218:d8a59b727f65

Fix spawnTaskManager
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Mon, 09 Jan 2017 05:23:20 +0900
parents c34e6aa10967
children de1ba77f94b4
files src/parallel_execution/CMakeLists.txt src/parallel_execution/TaskManager.c src/parallel_execution/context.h src/parallel_execution/main.c
diffstat 4 files changed, 33 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Mon Jan 09 01:18:13 2017 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Mon Jan 09 05:23:20 2017 +0900
@@ -23,7 +23,7 @@
   TARGET
       twice
   SOURCES 
-      main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c
+    main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c taskManager.c queue.c
 )
 
 GearsCommand(
--- a/src/parallel_execution/TaskManager.c	Mon Jan 09 01:18:13 2017 +0900
+++ b/src/parallel_execution/TaskManager.c	Mon Jan 09 05:23:20 2017 +0900
@@ -15,26 +15,26 @@
     return (union Data*)(taskManager);
 }
 
-__code spawnTaskManager(struct Context* context, struct Task* task, struct Element* element, struct Queue* queue, struct Queue* activeQueue, struct Queue* waitQueue) {
+__code spawnTaskManager(struct Context* context, struct TaskManagerImpl* taskManager, struct Queue* queue, struct Task* task, enum Code next) {
     if (task->idsCount == 0) {
         // enqueue activeQueue
-        queue->queue = (union Data*)activeQueue;
+        queue->queue = (union Data*)taskManager->activeQueue;
     } else {
         // enqueue waitQueue
-        queue->queue = (union Data*)waitQueue;
+        queue->queue = (union Data*)taskManager->taskQueue;
     }
-    queue->data = element->data;
-    queue->next = context->next;
+    queue->data = (union Data*)task;
+    queue->next = next;
     goto meta(context, queue->queue->Queue.put);
 }
 
 __code spawnTaskManager_stub(struct Context* context) {
     goto spawnTaskManager(context,
-            context->data[D_Element]->Element.data,
-            &context->data[D_Element]->Element,
+            (struct TaskManagerImpl *)context->data[D_TaskManager]->TaskManager.taskManager->TaskManager.taskManager,
             &context->data[D_Queue]->Queue,
-            context->data[D_TaskManagerImpl]->TaskManagerImpl.activeQueue,
-            context->data[D_TaskManagerImpl]->TaskManagerImpl.taskQueue);
+            context->data[D_TaskManager]->TaskManager.task,
+            context->data[D_TaskManager]->TaskManager.next
+            );
 }
 
 __code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) {
@@ -55,5 +55,5 @@
 }
 
 __code shutdownTaskManager_stub(struct Context* context) {
-    goto shutdownTaskManager(context, &context->data[D_LoopCounter]->loopCounter, &context->data[D_Worker]->Worker);
+    goto shutdownTaskManager(context, &context->data[D_LoopCounter]->LoopCounter, &context->data[D_Worker]->Worker);
 }
--- a/src/parallel_execution/context.h	Mon Jan 09 01:18:13 2017 +0900
+++ b/src/parallel_execution/context.h	Mon Jan 09 05:23:20 2017 +0900
@@ -74,11 +74,13 @@
         struct Tree* tree;
     } LoopCounter;
     struct TaskManager {
+        union Data* taskManager;
         int numWorker;
         enum Code spawn;
         enum Code shutdown;
         enum Code deadLockDetected;
         enum Code next;
+        struct Task* task;
         struct Worker* workers;
     } TaskManager;
     struct TaskManagerImpl {
--- a/src/parallel_execution/main.c	Mon Jan 09 01:18:13 2017 +0900
+++ b/src/parallel_execution/main.c	Mon Jan 09 05:23:20 2017 +0900
@@ -6,6 +6,8 @@
 #include "origin_cs.h"
 
 extern __code initContext(struct Context* context);
+extern union Data* createRedBlackTree(struct Context* context);
+extern union Data* createTaskManager(struct Context* context);
 extern void allocator(struct Context* context);
 
 int cpu_num = 1;
@@ -73,9 +75,6 @@
     int i = loopCounter->i;
 
     if ((length/split*i) < length) {
-        allocate->size = sizeof(struct Array);
-        allocator(context);
-
         goto meta(context, C_createData2);
     }
 
@@ -84,7 +83,11 @@
 }
 
 __code createData1_stub(struct Context* context) {
-    goto createData1(context, &context->data[D_Allocate]->Allocate, &context->data[D_LoopCounter]->LoopCounter);
+    LoopCounter* loopCounter = Gearef(context, LoopCounter);
+    loopCounter->i = 0;
+    loopCounter->tree = &createRedBlackTree(context)->Tree;
+    context->data[D_Tree]->Tree.tree = (union Data*)loopCounter->tree;
+    goto createData1(context, Gearef(context, Allocate), Gearef(context, LoopCounter));
 }
 
 __code createData2(struct Context* context, struct LoopCounter* loopCounter, struct Array* array, struct Node* node, Tree* tree) {
@@ -104,79 +107,35 @@
 }
 
 __code createData2_stub(struct Context* context) {
+    Array* array = &ALLOCATE(context, Array)->Array;
     goto createData2(context,
-            &context->data[D_LoopCounter]->LoopCounter,
-            &context->data[context->dataNum]->Array,
-            &context->data[D_Node]->Node,
+            Gearef(context, LoopCounter),
+            array,
+            Gearef(context, Node),
             Gearef(context, Tree));
 }
 
-__code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Element* element) {
+__code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Task* task) {
     task->code = C_twice;
     task->idsCount = 0;
 
-    element->data = (union Data *)task;
-
-    context->next = C_createData1;
+    taskManager->task = task;
+    taskManager->next = C_createData1;
     loopCounter->i++;
 
-    goto meta(context, C_createTask1);
+    goto meta(context, taskManager->taskManager->TaskManager.spawn);
 }
 
 __code createTask1_stub(struct Context* context) {
     Task* task = &ALLOCATE(context, Task)->Task;
+    TaskManager* taskManager = &createTaskManager(context)->TaskManager;
+    context->data[D_TaskManager]->TaskManager.taskManager = (union Data*)taskManager;
     goto createTask1(context,
-            &context->data[D_LoopCounter]->LoopCounter,
-            task,
-            &context->data[D_Element]->Element);
+            Gearef(context, LoopCounter),
+            Gearef(context, TaskManager),
+            task);
 }
 
-//__code createTask4(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct OdsQueue* waitI, struct Element* element, struct Queue* activeQueue) {
-//    int i = loopCounter->i;
-//
-//    task->code = TaskC;
-//    task->key = i;
-//    task->waitMe = waitMe;
-//    task->waitI = waitI;
-//    task->idsCount = 1;
-//
-//    element->data = (union Data *)task;
-//
-//    context->next = CreateData1;
-//    loopCounter->i++;
-//
-//    goto meta_createTask2(context, activeQueue, PutQueue1);
-//}
-//
-//__code createTask4_stub(struct Context* context) {
-//    goto createTask2(context,
-//            &context->data[LoopCounter]->loopCounter,
-//            &context->data[context->dataNum]->task,
-//            &context->data[context->dataNum-1]->queue,
-//            &context->data[context->dataNum-2]->odsQueue,
-//            &context->data[Element]->element,
-//            &context->data[ActiveQueue]->queue);
-//}
-//
-//__code createTask5(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Task* slave, struct Element* element) {
-//    int i = loopCounter->i;
-//
-//    task->code = TaskB;
-//    task->key = i;
-//    element->data = (union Data *)task;
-//
-//    context->next = CreateData1;
-//    loopCounter->i++;
-//
-//    goto meta(context, WaitFor1);
-//}
-//
-//__code createTask5_stub(struct Context* context) {
-//    goto createTask2(context,
-//            &context->data[context->dataNum]->task,
-//            &context->data[Element]->element);
-//}
-
 __code createWorker1(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) {
     int i = loopCounter->i;