diff src/parallel_execution/examples/twice/createArray.cbc @ 438:7679093bdd72

Work CUDAtwice
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Mon, 06 Nov 2017 00:11:43 +0900
parents 85b0ddbf458e
children 7d67c9cf09ee
line wrap: on
line diff
--- a/src/parallel_execution/examples/twice/createArray.cbc	Sat Nov 04 08:30:25 2017 +0900
+++ b/src/parallel_execution/examples/twice/createArray.cbc	Mon Nov 06 00:11:43 2017 +0900
@@ -1,24 +1,39 @@
 #include <stdio.h>
-
 #include "../../../context.h"
 
 extern int length;
 extern int split;
-extern int* array_ptr;
 
-__code createArray(__code next(struct Array* output, ...)) {
+__code createArray(__code next(struct Array* output, struct Time* output1, ...), struct LoopCounter* loopCounter) {
     struct Array* output = *O_output;
-    output->prefix = length/split;
-    output->array  = array_ptr;
-    output->size   = length;
+    struct Time* output1 = *O_output1;
+    int i = loopCounter->i;
+    if (i == 0){
+        output->array = (Int*)ALLOCATE_ARRAY(context, Int, length);
+        output->prefix = length/split;
+    }
+    if (i == GET_LEN(output->array)){
+        printf("created Array\n");
+        loopCounter->i = 0;
+        Gearef(context, Time)->time = (union Data*)output1;
+        Gearef(context, Time)->next = context->next;
+        *O_output = output;
+        *O_output1 = output1;
+        goto meta(context, output1->start);
+    }
+    output->array[i] = i;
+    loopCounter->i++;
     *O_output = output;
-    printf("created Array\n");
-    goto meta(context, context->next);
+    *O_output1 = output1;
+    goto meta(context, C_createArray);
 }
 
 __code createArray_stub(struct Context* context) {
     Array** O_output = (struct Array **)&context->data[context->odg];
+    Time** O_output1 = (struct Time**)&context->data[context->odg+1];
     goto createArray(context,
-                     context->next,
-                     O_output);
+            context->next,
+            O_output,
+            O_output1,
+            Gearef(context, LoopCounter));
 }