comparison src/parallel_execution/OneDimIterator.cbc @ 374:fb50cf8aa615

Add Iterator Interface
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Tue, 18 Jul 2017 15:14:08 +0900
parents
children ad44fdb11433
comparison
equal deleted inserted replaced
373:03fdea4ef680 374:fb50cf8aa615
1 #include "../context.h"
2 #include <stdio.h>
3
4 Iterator createOneDimIterator(struct Context* context, int x) {
5 struct Iterator* iterator = new Iterator();
6 struct OneDimIterator* oneDimIterator = new OneDimIterator();
7 iterator->iterator = (union Data*)oneDimIterator;
8 iterator->exec = C_execOneDimIterator;
9 iterator->barrier = C_barrierOneDimItearator;
10 oneDimIterator->x = x;
11 oneDimIterator->count = x;
12 iterator->loopCounter = new LoopCounter();
13 iterator->loopCounter->i = 0;
14 oneDimIterator->exec = C_execOneDimIterator;
15 }
16
17 __code execOneDimIterator(struct OneDimIterator* oneDimIterator, struct TaskManager* taskManager, struct context* task, __code next(...)) {
18 if (oneDimIterator->loopCounter->i == oneDimIterator->x) {
19 oneDimIterator->loopCounter->i = 0;
20 goto next(...);
21 }
22 struct context* iterate_task = NEW(struct Context);
23 *iterate_task = *task;
24 task->iterate = 1;
25 oneDimIterator->loopCounter->i++;
26 taskManager->taskManager = (union Data*)task->taskManager;
27 taskManager->task = iterate_task;
28 taskManager->next = C_execOneDimIterator;
29 goto meta(context, C_execOneDimIterator);
30 }
31
32 __code barrierOneDimIterator(struct OneDimIterator* oneDimIterator, struct context* task, __code next(...), __code whenWait(...)) {
33 if (__sync_fetch_and_sub(&oneDimIterator->count, 1) == 1) {
34 goto next(...);
35 }
36 goto whenWait(...);
37 }