Mercurial > hg > GearsTemplate
annotate 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 |
rev | line source |
---|---|
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include "../context.h" |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <stdio.h> |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 Iterator createOneDimIterator(struct Context* context, int x) { |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 struct Iterator* iterator = new Iterator(); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 struct OneDimIterator* oneDimIterator = new OneDimIterator(); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 iterator->iterator = (union Data*)oneDimIterator; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 iterator->exec = C_execOneDimIterator; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 iterator->barrier = C_barrierOneDimItearator; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 oneDimIterator->x = x; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 oneDimIterator->count = x; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 iterator->loopCounter = new LoopCounter(); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 iterator->loopCounter->i = 0; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 oneDimIterator->exec = C_execOneDimIterator; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 __code execOneDimIterator(struct OneDimIterator* oneDimIterator, struct TaskManager* taskManager, struct context* task, __code next(...)) { |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 if (oneDimIterator->loopCounter->i == oneDimIterator->x) { |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 oneDimIterator->loopCounter->i = 0; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 goto next(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 struct context* iterate_task = NEW(struct Context); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 *iterate_task = *task; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 task->iterate = 1; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 oneDimIterator->loopCounter->i++; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 taskManager->taskManager = (union Data*)task->taskManager; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 taskManager->task = iterate_task; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 taskManager->next = C_execOneDimIterator; |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 goto meta(context, C_execOneDimIterator); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 __code barrierOneDimIterator(struct OneDimIterator* oneDimIterator, struct context* task, __code next(...), __code whenWait(...)) { |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 if (__sync_fetch_and_sub(&oneDimIterator->count, 1) == 1) { |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 goto next(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 goto whenWait(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 } |