changeset 401:408b4aab7610

Supported par goto iterate statement for perl script
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Tue, 29 Aug 2017 21:50:57 +0900
parents 2d375c583064
children e958a409943c
files src/parallel_execution/CMakeLists.txt src/parallel_execution/cuda.c src/parallel_execution/generate_stub.pl src/parallel_execution/test/oneDimIterator_test.cbc src/parallel_execution/test/printIterator.cbc
diffstat 5 files changed, 30 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Tue Aug 29 04:29:50 2017 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Tue Aug 29 21:50:57 2017 +0900
@@ -104,7 +104,7 @@
   TARGET
   oneDimIterator_test
   SOURCES
-      test/oneDimIterator_test.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc OneDimIterator.cbc TimeImpl.cbc
+      test/oneDimIterator_test.cbc test/printIterator.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc OneDimIterator.cbc TimeImpl.cbc
 )
 
 GearsCommand(
--- a/src/parallel_execution/cuda.c	Tue Aug 29 04:29:50 2017 +0900
+++ b/src/parallel_execution/cuda.c	Tue Aug 29 21:50:57 2017 +0900
@@ -116,4 +116,3 @@
 //        checkCudaErrors(cuStreamDestroy(worker->stream[i]));
     checkCudaErrors(cuCtxDestroy(worker->cuCtx));
 }
-
--- a/src/parallel_execution/generate_stub.pl	Tue Aug 29 04:29:50 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Tue Aug 29 21:50:57 2017 +0900
@@ -416,10 +416,18 @@
                 # convert it to the parallel
                 my $prev = $1;
                 my $codeGearName = $2;
+                my $inputCount = $codeGear{$codeGearName}->{'input'};
+                my $outputCount = $codeGear{$codeGearName}->{'output'};
                 my @dataGears = split(/,\s*/, $3);
                 my $nextCodeGear = pop(@dataGears);
-                my $inputCount = $codeGear{$codeGearName}->{'input'};
-                my $outputCount = $codeGear{$codeGearName}->{'output'};
+                my $iterateCount;
+                # parse examples 'par goto(.., iterate(10), exit);'
+                if ($3 =~ /iterate\((\d*)\)/) {
+                    $iterateCount = $1;
+                    $inputCount--;
+                    # pop iterate statement
+                    pop(@dataGears);
+                }
                 if (! $inParGoto) {
                     $inParGoto = 1;
                     print $fd "${prev}struct SingleLinkedQueue* queue = &context->tasks->queue->SingleLinkedQueue;\n";
@@ -437,6 +445,10 @@
 ${prev}task->maxOdg = task->odg + $outputCount;
 EOFEOF
                 print $fd $initTask;
+                if (defined $iterateCount) {
+                    print $fd "${prev}task->iterate = 0;\n";
+                    print $fd "${prev}task->iterator = createOneDimIterator(context, $iterateCount);\n";
+                }
                 for my $i (0..$inputCount-1) {
                     print $fd "${prev}task->data[task->idg+$i] = (union Data*)@dataGears[$i];\n";
                 }
--- a/src/parallel_execution/test/oneDimIterator_test.cbc	Tue Aug 29 04:29:50 2017 +0900
+++ b/src/parallel_execution/test/oneDimIterator_test.cbc	Tue Aug 29 21:50:57 2017 +0900
@@ -82,25 +82,9 @@
     goto meta(context, taskManager->taskManager->TaskManager.shutdown);
 }
 
-__code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
-    struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 1);
-
-    // par goto printIterator(iterate(10))
-    struct Context* task = NEW(struct Context);
-    initContext(task);
-    task->iterate = 0;
-    task->iterator = createOneDimIterator(context, 10);
-    task->idgCount = 0;
-    task->next = C_printIterator;
-    task->idg = task->dataNum;
-    task->maxIdg = task->idg;
-    task->odg = task->maxIdg;
-    task->maxOdg = task->odg;
-
-    tasks[0] = task;
-    taskManager->contexts = tasks;
-    taskManager->next1 = C_createTask1;
-    goto meta(context, taskManager->taskManager->TaskManager.spawnTasks);
+__code createTask2(struct TaskManager* taskManager) {
+    par goto printIterator(iterate(10), exit);
+    goto createTask1();
 }
 
 void init(int argc, char** argv) {
@@ -123,14 +107,3 @@
     main_context->next = C_initDataGears;
     goto start_code(main_context);
 }
-
-__code printIterator(struct Integer* x, __code next(...)) {
-    printf("%d\n", x->value);
-    goto meta(context, next);
-}
-
-__code printIterator_stub(struct Context* context) {
-    goto printIterator(context,
-                       &context->data[context->idg]->Integer,
-                       context->next);
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/test/printIterator.cbc	Tue Aug 29 21:50:57 2017 +0900
@@ -0,0 +1,12 @@
+#include "../../context.h"
+#include <stdio.h>
+__code printIterator(struct Integer* x, __code next(...)) {
+    printf("%d\n", x->value);
+    goto meta(context, next);
+}
+
+__code printIterator_stub(struct Context* context) {
+    goto printIterator(context,
+                       &context->data[context->idg]->Integer,
+                       context->next);
+}