changeset 352:3e01e963eb2d

Fix compile error for calc example but not work
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Fri, 16 Jun 2017 16:29:27 +0900
parents 3529c7e93c4f
children b07078bd1f2c
files src/parallel_execution/CMakeLists.txt src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/context.h src/parallel_execution/examples/calc.cbc src/parallel_execution/generate_context.pl
diffstat 5 files changed, 63 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Thu Jun 08 15:44:39 2017 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Fri Jun 16 16:29:27 2017 +0900
@@ -67,7 +67,7 @@
   TARGET
       calc
   SOURCES 
-      examples/calc.cbc examples/Add.cbc examples/Mult.cbc examples/calc.cbc SingleLinkedStack.cbc CPUWorker.cbc time.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc SemaphoreImpl.cbc
+      examples/calc.cbc examples/Add.cbc examples/Mult.cbc examples/calc.cbc CPUWorker.cbc time.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc SemaphoreImpl.cbc
 )
 
 if (${USE_CUDA})
--- a/src/parallel_execution/TaskManagerImpl.cbc	Thu Jun 08 15:44:39 2017 +0900
+++ b/src/parallel_execution/TaskManagerImpl.cbc	Fri Jun 16 16:29:27 2017 +0900
@@ -13,7 +13,6 @@
     taskManager->gpu = numIO;
     taskManager->cpu = numIO+numGPU;
     taskManager->maxCPU = numIO+numGPU+numCPU;
-    taskManager->createTask = C_createTask;
     taskManager->spawn = C_spawnTaskManager;
     taskManager->setWaitTask = C_setWaitTask;
     taskManager->shutdown  = C_shutdownTaskManager;
@@ -21,6 +20,8 @@
     taskManagerImpl -> activeQueue = createSingleLinkedQueue(context);
     taskManagerImpl -> taskQueue = createSingleLinkedQueue(context);
     taskManagerImpl -> numWorker = taskManager->maxCPU;
+    taskManagerImpl -> loopCounter = new LoopCounter();
+    taskManagerImpl -> loopCounter -> i = 0;
     createWorkers(context, taskManager, taskManagerImpl);
     taskManager->taskManager = (union Data*)taskManagerImpl;
     return taskManager;
@@ -52,28 +53,26 @@
     }
 }
 
-__code createTask(struct TaskManager* taskManager) {
-    taskManager->context = NEW(struct Context);
-    initContext(taskManager->context);
-    taskManager->context->taskManager = (struct TaskManager*)taskManager->taskManager;
-    taskManager->context->idg = taskManager->context->dataNum;
-    goto meta(context, C_setWorker);
-}
-
-__code setWorker(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) {
+__code setWorker(struct TaskManagerImpl* taskManager, struct Context* task) {
     task->workerId = taskManager->sendWorkerIndex;
     if(++taskManager->sendWorkerIndex >= taskManager->numWorker) {
         taskManager->sendWorkerIndex = 0;
     }
-    goto next(...);
+    goto meta(context, C_setWaitTask);
 }
 
 __code setWorker_stub(struct Context* context) {
     TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
-    goto setWorker(context, taskManager, Gearef(context, TaskManager)->context, Gearef(context, TaskManager)->next);
+    int i = taskManager->loopCounter->i;
+    struct Context** contexts = Gearef(context, TaskManager)->contexts;
+    struct Context* task = contexts[i];
+    if(i != GET_SIZE(contexts) - 1) {
+        taskManager->loopCounter->i++;
+    }
+    goto setWorker(context, taskManager, task);
 }
 
-__code setWaitTask(struct TaskManager* taskManager, struct Queue* queue, struct Context* task, struct LoopCounter* loopCounter, __code next(...)) {
+__code setWaitTask(struct Queue* queue, struct Context* task, struct LoopCounter* loopCounter, __code next(...)) {
     int i = loopCounter->i;
     if(task->idg + i < task->maxIdg) {
         loopCounter->i++;
@@ -82,16 +81,24 @@
         queue->data = (Data *)task;
         goto meta(context, queue->queue->Queue.put);
     }
-    goto meta(context, taskManager->taskManager->TaskManager.spawn);
+    loopCounter->i = 0;
+    goto next(...);
 }
 
 __code setWaitTask_stub(struct Context* context) {
-    TaskManager* taskManager = Gearef(context, TaskManager);
-    struct Context* task = Gearef(context, TaskManager)->context;
-    goto setWaitTask(context, taskManager, Gearef(context, Queue), task, Gearef(task, LoopCounter), Gearef(context, TaskManager)->next);
+    TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
+    int i = taskManager->loopCounter->i;
+    struct Context** contexts = Gearef(context, TaskManager)->contexts;
+    struct Context* task = contexts[i];
+    enum Code next = C_setWorker;
+    if(i == GET_SIZE(contexts) - 1) {
+        taskManager->loopCounter->i = 0;
+        next = C_spawnTaskManager;
+    }
+    goto setWaitTask(context, Gearef(context, Queue), task, Gearef(task, LoopCounter), next);
 }
 
-__code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) {
+__code spawnTaskManager(struct TaskManagerImpl* taskManager, struct Context* task, __code next(...)) {
     if (task->idgCount == 0) {
         goto meta(context, C_taskSend);
     } else {
@@ -102,12 +109,20 @@
 
 __code spawnTaskManager_stub(struct Context* context) {
     TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
-    pthread_mutex_lock(&taskManager->mutex);
+    int i = taskManager->loopCounter->i;
+    struct Context** contexts = Gearef(context, TaskManager)->contexts;
+    struct Context* task = contexts[i];
+    enum Code next = Gearef(context, TaskManager)->next;
+    if(i == GET_SIZE(contexts) - 1) {
+        taskManager->loopCounter->i = 0;
+    } else {
+        taskManager->loopCounter->i++;
+        next = C_spawnTaskManager;
+    }
     goto spawnTaskManager(context,
             taskManager,
-            Gearef(context, Queue),
-            Gearef(context, TaskManager)->context,
-            Gearef(context, TaskManager)->next);
+            task,
+            next);
 }
 
 __code taskSend(struct TaskManagerImpl* taskManager, struct Queue* queue, struct Context* task, __code next(...)) {
--- a/src/parallel_execution/context.h	Thu Jun 08 15:44:39 2017 +0900
+++ b/src/parallel_execution/context.h	Fri Jun 16 16:29:27 2017 +0900
@@ -53,6 +53,7 @@
 
 #define GET_META(dseg) ((struct Meta*)(((void*)dseg) - sizeof(struct Meta)))
 #define GET_TYPE(dseg) (GET_META(dseg)->type)
+#define GET_SIZE(dseg) (GET_META(dseg)->size)
 #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait)
 
 #define Gearef(context, t) (&(context)->data[D_##t]->t)
@@ -109,25 +110,18 @@
     struct LoopCounter {
         int i;
     } LoopCounter;
-    struct CodeGear {
-        union Data* CodeGear;
-        enum Code code;
-        union Data* dataGears[10];
-        enum Code next;
-    } CodeGear;
     struct TaskManager {
 #ifdef USE_CUDA_MAIN_THREAD
         volatile 
 #endif
         union Data* taskManager;
-        enum Code createTask; // create NEW  contexts for execution & argument
         enum Code spawn;      // start NEW context on the worker
         enum Code setWaitTask;
         enum Code shutdown;
-
         enum Code next;
         enum Code task;
         struct Context* context;
+        struct Context** contexts;
         union Data* data;
         int worker;
         int cpu;
@@ -142,6 +136,7 @@
         struct Queue* activeQueue;
         struct Queue* taskQueue;
         struct Worker** workers;
+        struct LoopCounter* loopCounter;
     } TaskManagerImpl;
     struct Worker {
         union Data* worker;
--- a/src/parallel_execution/examples/calc.cbc	Thu Jun 08 15:44:39 2017 +0900
+++ b/src/parallel_execution/examples/calc.cbc	Fri Jun 16 16:29:27 2017 +0900
@@ -103,10 +103,13 @@
     goto meta(context, taskManager->taskManager->TaskManager.shutdown);
 }
 
-__code createTask2(LoopCounter* loopCounter, TaskManager* taskManager, Integer *integer1, Integer *integer2, Integer *integer3) {
-    int i = loopCounter->i;
-    integer1->value = i;
-    integer2->value = i+1;
+__code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
+    struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 2);
+
+    Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
+    Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
+    Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
+    // par goto mult(integer1, integer2, integer3, __exit);
     struct Context* task = NEW(struct Context);
     initContext(task);
     task->taskManager = &taskManager->taskManager->TaskManager;
@@ -119,54 +122,30 @@
     task->odg = task->maxIdg;
     task->data[task->odg] = (union Data*)integer3;
     task->maxOdg = task->odg + 1;
-    taskManager->context = task;
-    taskManager->next = C_createTask3;
-    goto meta(context, taskManager->taskManager->TaskManager.setWaitTask);
-}
+    tasks[0] = task;
 
-__code createTask2_stub(struct Context* context) {
-    Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    goto createTask2(context,
-            Gearef(context, LoopCounter),
-            Gearef(context, TaskManager),
-            integer1,
-            integer2,
-            integer3);
-}
-
-__code createTask3(LoopCounter* loopCounter, TaskManager* taskManager, Integer *integer1, Integer *integer2, Integer *integer3) {
-    int i = loopCounter->i;
-    integer1->value = i;
-    integer2->value = i+1;
-    struct Context* task = NEW(struct Context);
+    Integer* integer4 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
+    Integer* integer5 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
+    // par goto add(integer2, integer3, integer1, __exit);
+    task = NEW(struct Context);
     initContext(task);
     task->taskManager = &taskManager->taskManager->TaskManager;
     task->next = C_add;
     task->idgCount = 2;
     task->idg = task->dataNum;
-    task->data[task->idg] = (union Data*)integer1;
-    task->data[task->idg+1] = (union Data*)integer2;
+    task->data[task->idg] = (union Data*)integer4;
+    task->data[task->idg+1] = (union Data*)integer5;
     task->maxIdg = task->idg + 2;
     task->odg = task->maxIdg;
-    task->data[task->odg] = (union Data*)integer3;
+    task->data[task->odg] = (union Data*)integer1;
     task->maxOdg = task->odg + 1;
-    taskManager->context = task;
-    taskManager->next = C_createTask3;
-    goto meta(context, taskManager->taskManager->TaskManager.setWaitTask);
-}
+    tasks[1] = task;
 
-__code createTask3_stub(struct Context* context) {
-    Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer;
-    goto createTask3(context,
-            Gearef(context, LoopCounter),
-            Gearef(context, TaskManager),
-            integer1,
-            integer2,
-            integer3);
+    //goto taskManager->setWaitTask(createTask1);
+    taskManager->contexts = tasks;
+    // goto crateTask1();
+    taskManager->next = C_createTask1;
+    goto meta(context, taskManager->taskManager->TaskManager.setWaitTask);
 }
 
 void init(int argc, char** argv) {
--- a/src/parallel_execution/generate_context.pl	Thu Jun 08 15:44:39 2017 +0900
+++ b/src/parallel_execution/generate_context.pl	Fri Jun 16 16:29:27 2017 +0900
@@ -108,6 +108,7 @@
         if (/struct (\w+) \{/) {
             $dataGear{$1} = $1;
         }
+        $dataGear{"Context"} = "Context";
     }
 }