annotate TaskManager/Test/Sum/main.cpp @ 132:e7c80537b6aa

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