annotate src/parallel_execution/TaskIterator.cbc @ 462:8d7e5d48cad3

Running CPU examples
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Wed, 20 Dec 2017 22:05:08 +0900
parents 95f58f2b2c0e
children ac244346c85d
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"
462
8d7e5d48cad3 Running CPU examples
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 456
diff changeset
2 #include "Iterator.h"
456
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <stdio.h>
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 createTaskIterator(struct Context, struct List list) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 struct Iterator* iterator = new Iterator();
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 struct TaskIterator* taskIterator = new TaskIterator();
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 iterator->itearot = (union Data*)taskIterator;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 iterator->exec = C_execTaskIterator;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 iterator->barrier = C_barrierTaskIterator;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 taskIterator->taskList = list;
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
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 __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
15 if (iterator->list->next == null) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 goto next(...);
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 }
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 iterator->list = list->next;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 struct Context* task = (struct Context*)iterator->list->data;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 struct TaskManager taskManager = task->taskManager;
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 taskManager->spawn(task, C_execTaskIterator);
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
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 __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
25 if (__sync_fetch_and_sub(&iterator->count, 1) == 1) {
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 goto next(...);
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 goto whenWait(...);
95f58f2b2c0e Add TaskIterator
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }