Mercurial > hg > GearsTemplate
annotate src/parallel_execution/OneDimIterator.cbc @ 382:f1d111e293c4
Enable Timer for bitonicSort
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 Jul 2017 20:05:08 +0900 |
parents | 9049c19036fd |
children | 89a9e9c14498 |
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 |
378
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
17 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
|
18 struct Context* task1 = NEW(struct Context); |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
19 initContext(task1); |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
20 task1->taskManager = task->taskManager; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
21 task1->next = task->next; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
22 task1->iterate = 1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
23 task1->iterator = task->iterator; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
24 task1->idgCount = task->idgCount; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
25 task1->idg = task->idg; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
26 task1->maxIdg = task->maxIdg; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
27 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
|
28 task1->data[i] = task->data[i]; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
29 } |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
30 |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
31 // 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
|
32 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
|
33 dataX->value = x; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
34 task1->data[task1->maxIdg++] = (union Data*)dataX; |
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 task1->odg = task->odg + 1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
37 task1->maxOdg = task->maxOdg + 1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
38 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
|
39 task1->data[i] = task->data[i-1]; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
40 } |
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 return task1; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
43 } |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
44 |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
45 __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
|
46 int i = iterator->loopCounter->i; |
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
47 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
|
48 iterator->loopCounter->i = 0; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 goto next(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 } |
378
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
51 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
|
52 iterator->loopCounter->i++; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 taskManager->taskManager = (union Data*)task->taskManager; |
378
9049c19036fd
Add iterator index
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
376
diff
changeset
|
54 taskManager->context = iterateTask; |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 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
|
56 goto meta(context, task->taskManager->spawn); |
374
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
59 __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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 } |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
66 |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
67 __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
|
68 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
|
69 goto next(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 } |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 goto whenWait(...); |
fb50cf8aa615
Add Iterator Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 } |
375
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
73 |
ad44fdb11433
Fix compile error but not work
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
374
diff
changeset
|
74 __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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 } |