annotate src/parallel_execution/TaskIterator.cbc @ 456:95f58f2b2c0e

Add TaskIterator
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Mon, 11 Dec 2017 16:26:55 +0900
parents
children 8d7e5d48cad3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
456
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "../context.h"
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdio.h>
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 createTaskIterator(struct Context, struct List list) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 struct Iterator* iterator = new Iterator();
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 struct TaskIterator* taskIterator = new TaskIterator();
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 iterator->itearot = (union Data*)taskIterator;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 iterator->exec = C_execTaskIterator;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 iterator->barrier = C_barrierTaskIterator;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 taskIterator->taskList = list;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 }
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 __code execTaskIterator(struct taskIterator* iterator, struct TaskManager* taskManager, struct Context* task, __code next(...)) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 if (iterator->list->next == null) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 goto next(...);
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 }
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 iterator->list = list->next;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 struct Context* task = (struct Context*)iterator->list->data;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 struct TaskManager taskManager = task->taskManager;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 taskManager->spawn(task, C_execTaskIterator);
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 __code barrierTaskIterator(struct MultiDimIterator* iterator, struct Context* task, __code next(...), __code whenWait(...)) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 if (__sync_fetch_and_sub(&iterator->count, 1) == 1) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 goto next(...);
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 goto whenWait(...);
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }