Mercurial > hg > Gears > GearsAgda
annotate src/parallel_execution/OneDimIterator.cbc @ 386:89a9e9c14498
Add comment to createOneDimiterateTask
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 26 Jul 2017 18:57:19 +0900 |
parents | f1d111e293c4 |
children |
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 |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
4 Iterator* createOneDimIterator(struct Context* context, int x) { |
374
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; |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
9 iterator->barrier = C_barrierOneDimIterator; |
374
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; |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
12 oneDimIterator->loopCounter = new LoopCounter(); |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
13 oneDimIterator->loopCounter->i = 0; |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
14 return iterator; |
374
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 |
386
89a9e9c14498
Add comment to createOneDimiterateTask
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
382
diff
changeset
|
17 /** |
89a9e9c14498
Add comment to createOneDimiterateTask
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
382
diff
changeset
|
18 * create iterateTask with index, that copy from task argument |
89a9e9c14498
Add comment to createOneDimiterateTask
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
382
diff
changeset
|
19 * @return created iterateTask |
89a9e9c14498
Add comment to createOneDimiterateTask
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
382
diff
changeset
|
20 * @param task task of the copy source |
89a9e9c14498
Add comment to createOneDimiterateTask
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
382
diff
changeset
|
21 * @x index |
89a9e9c14498
Add comment to createOneDimiterateTask
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
382
diff
changeset
|
22 */ |
378
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
23 struct Context* createOneDimIterateTask(struct Context* task, int x) { |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
24 struct Context* task1 = NEW(struct Context); |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
25 initContext(task1); |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
26 task1->taskManager = task->taskManager; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
27 task1->next = task->next; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
28 task1->iterate = 1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
29 task1->iterator = task->iterator; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
30 task1->idgCount = task->idgCount; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
31 task1->idg = task->idg; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
32 task1->maxIdg = task->maxIdg; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
33 for(int i = task1->idg; i < task1->maxIdg; i++) { |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
34 task1->data[i] = task->data[i]; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
35 } |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
36 |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
37 // create index data gear and register input data to iterate task |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
38 struct Integer* dataX = &ALLOCATE_DATA_GEAR(task1, Integer)->Integer; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
39 dataX->value = x; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
40 task1->data[task1->maxIdg++] = (union Data*)dataX; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
41 |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
42 task1->odg = task->odg + 1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
43 task1->maxOdg = task->maxOdg + 1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
44 for (int i = task1->odg; i < task1->maxOdg; i++) { |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
45 task1->data[i] = task->data[i-1]; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
46 } |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
47 |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
48 return task1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
49 } |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
50 |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
51 __code execOneDimIterator(struct OneDimIterator* iterator, struct TaskManager* taskManager, struct Context* task, __code next(...)) { |
378
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
52 int i = iterator->loopCounter->i; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
53 if (i == iterator->x) { |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
54 iterator->loopCounter->i = 0; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 goto next(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 } |
378
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
57 struct Context* iterateTask = createOneDimIterateTask(task, i); |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
58 iterator->loopCounter->i++; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 taskManager->taskManager = (union Data*)task->taskManager; |
378
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
60 taskManager->context = iterateTask; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 taskManager->next = C_execOneDimIterator; |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
62 goto meta(context, task->taskManager->spawn); |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
65 __code execOneDimIterator_stub(struct Context* context) { |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
66 OneDimIterator* iterator = (OneDimIterator*)GearImpl(context, Iterator, iterator); |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
67 TaskManager* taskManager = Gearef(context, TaskManager); |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
68 Context* task = Gearef(context, Iterator)->task; |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
69 enum Code next = Gearef(context, Iterator)->next; |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
70 goto execOneDimIterator(context, iterator, taskManager, task, next); |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
71 } |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
72 |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
73 __code barrierOneDimIterator(struct OneDimIterator* iterator, struct Context* task, __code next(...), __code whenWait(...)) { |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
74 if (__sync_fetch_and_sub(&iterator->count, 1) == 1) { |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 goto next(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 goto whenWait(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 } |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
79 |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
80 __code barrierOneDimIterator_stub(struct Context* context) { |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
81 OneDimIterator* iterator = (OneDimIterator*)GearImpl(context, Iterator, iterator); |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
82 Context* task = Gearef(context, Iterator)->task; |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
83 enum Code next = Gearef(context, Iterator)->next; |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
84 enum Code whenWait = Gearef(context, Iterator)->whenWait; |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
85 goto barrierOneDimIterator(context, iterator, task, next, whenWait); |
382
f1d111e293c4
Enable Timer for bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
378
diff
changeset
|
86 } |