3
|
1 #include <stdio.h>
|
5
|
2 #include <string.h>
|
3
|
3 #include "TaskManager.h"
|
|
4
|
|
5 #define MAX 1024
|
|
6
|
14
|
7 TaskManager *manager;
|
|
8
|
|
9 int sum(void*, void*);
|
|
10 int sum2(void*, void*);
|
|
11
|
3
|
12 int data[MAX] __attribute__((aligned(16)));
|
|
13 int buff[MAX] __attribute__((aligned(16)));
|
|
14 int out[MAX] __attribute__((aligned(16)));
|
|
15
|
14
|
16 int
|
|
17 sum(void *wbuf, void *rbuf)
|
3
|
18 {
|
14
|
19 int *ret = (int*)wbuf;
|
|
20 int *data = (int*)rbuf;
|
3
|
21 int i;
|
14
|
22
|
|
23 *ret = 0;
|
|
24
|
|
25 for (i = 0; i < 16; i++) {
|
|
26 *ret += data[i];
|
|
27 }
|
|
28
|
|
29 return sizeof(int);
|
|
30 }
|
|
31
|
|
32 int
|
|
33 sum2(void *wbuf, void *rbuf)
|
|
34 {
|
|
35 int *ret = (int*)wbuf;
|
|
36 int *data = (int*)rbuf;
|
|
37 int i;
|
|
38
|
|
39 *ret = 0;
|
|
40
|
|
41 for (i = 0; i < 64; i++) {
|
|
42 *ret += data[i*4];
|
|
43 }
|
|
44
|
|
45 return sizeof(int);
|
|
46 }
|
|
47
|
|
48 int
|
|
49 init2(void *w, void *r)
|
|
50 {
|
|
51 int i, fd;
|
3
|
52 int div = MAX/16;
|
|
53
|
|
54 HTaskPtr *task = new HTaskPtr[div];
|
|
55 HTaskPtr last;
|
|
56
|
|
57 for (i = 0; i < MAX; i++) {
|
|
58 data[i] = i;
|
|
59 }
|
|
60
|
|
61 memset(buff, 0, sizeof(int)*1024);
|
|
62 memset(out, 0, sizeof(int)*1024);
|
|
63
|
14
|
64 fd = manager->open("Sum");
|
3
|
65 for (i = 0; i < div; i++) {
|
14
|
66 task[i] = manager->create_task(fd, sizeof(int)*16,
|
|
67 (unsigned int)&data[i*16],
|
|
68 (unsigned int)&buff[i*4],
|
3
|
69 NULL);
|
|
70 }
|
|
71
|
14
|
72 fd = manager->open("Sum2");
|
|
73 last = manager->create_task(fd, sizeof(int)*256,
|
|
74 (unsigned int)buff,
|
|
75 (unsigned int)&out[0], NULL);
|
3
|
76
|
|
77 for (i = 0; i < div; i++) {
|
|
78 manager->set_task_depend(task[i], last);
|
|
79 }
|
|
80 for (i = 0; i < div; i++) {
|
18
|
81 manager->spawn_task(task[i]);
|
3
|
82 }
|
18
|
83 manager->spawn_task(last);
|
14
|
84
|
|
85 return 0;
|
|
86 }
|
|
87
|
|
88
|
|
89 int
|
|
90 result(void *w, void *r)
|
|
91 {
|
3
|
92
|
|
93 printf("manager : %d\n", out[0]);
|
|
94
|
|
95 out[0] = 0;
|
14
|
96 for (int i = 0; i < MAX; i++) {
|
3
|
97 out[0] += i;
|
|
98 }
|
|
99
|
|
100 printf("for : %d\n", out[0]);
|
|
101
|
|
102 return 0;
|
|
103 }
|
14
|
104
|
|
105 int
|
|
106 init(void *w, void *r)
|
|
107 {
|
18
|
108 HTaskPtr init_task;
|
|
109 HTaskPtr finish_task;
|
14
|
110
|
|
111 int fd;
|
|
112
|
|
113 fd = manager->open("Init2");
|
|
114 init_task = manager->create_task(fd, 0, 0, 0, NULL);
|
18
|
115 manager->spawn_task(init_task);
|
|
116
|
14
|
117 fd = manager->open("Result");
|
|
118 finish_task = manager->create_task(fd, 0, 0, 0, NULL);
|
|
119 manager->set_task_depend(init_task, finish_task);
|
18
|
120 manager->spawn_task(finish_task);
|
14
|
121
|
|
122 return 0;
|
|
123 }
|
|
124
|
|
125 int
|
|
126 main(void)
|
|
127 {
|
|
128 manager = new TaskManager(1);
|
|
129 manager->init();
|
|
130
|
17
|
131 // ここは user 側で書かない...のか?
|
14
|
132 // 設定ファイルかなにかで読むとか?違うな
|
17
|
133 // あと、void* って書くのめんどくせ
|
14
|
134 manager->set_symbol("Init", (void*)init);
|
|
135 manager->set_symbol("Init2", (void*)init2);
|
|
136 manager->set_symbol("Result", (void*)result);
|
|
137 manager->set_symbol("Sum", (void*)sum);
|
|
138 manager->set_symbol("Sum2", (void*)sum2);
|
|
139
|
|
140 manager->set_init_task("Init");
|
|
141 manager->run();
|
|
142
|
20
|
143 manager->finish();
|
|
144 delete manager;
|
|
145
|
14
|
146 return 0;
|
|
147 }
|