Mercurial > hg > Members > kono > Cerium
comparison example/HelloWorld/main.cc @ 1040:1e243714cf3c
add TaskCreater test funciton..
author | yutaka@localhost.localdomain |
---|---|
date | Mon, 06 Dec 2010 18:03:21 +0900 |
parents | bba03a6843ba |
children |
comparison
equal
deleted
inserted
replaced
1035:ff0e6d00c060 | 1040:1e243714cf3c |
---|---|
5 #include "Func.h" | 5 #include "Func.h" |
6 | 6 |
7 extern void task_init(void); | 7 extern void task_init(void); |
8 | 8 |
9 static int count = 1; | 9 static int count = 1; |
10 static int spe_num = 1; | |
10 | 11 |
11 extern TaskManager *manager; | 12 extern TaskManager *manager; |
13 int use_task_creater = 0; | |
12 | 14 |
13 const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\ | 15 const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\ |
14 -cpu Number of SPE (default 1) \n\ | 16 -cpu Number of SPE (default 1) \n\ |
15 -count Number of task is print \"Hello, World!!\""; | 17 -count Number of task is print \"Hello, World!!\""; |
16 | 18 |
18 init(int argc, char **argv) | 20 init(int argc, char **argv) |
19 { | 21 { |
20 for (int i = 1; argv[i]; ++i) { | 22 for (int i = 1; argv[i]; ++i) { |
21 if (strcmp(argv[i], "-count") == 0) { | 23 if (strcmp(argv[i], "-count") == 0) { |
22 count = atoi(argv[++i]); | 24 count = atoi(argv[++i]); |
23 } | 25 } else if (strcmp(argv[i], "-cpu") == 0) { |
26 spe_num = atoi(argv[i+1]); | |
27 } else if (strcmp(argv[i], "-t") == 0) { | |
28 use_task_creater = 1; | |
29 } | |
30 | |
31 | |
24 | 32 |
25 } | 33 } |
26 | 34 |
27 return 0; | 35 return 0; |
28 } | 36 } |
29 | 37 |
38 | |
39 static void simple_task_creater(int in_total_size, int out_total_size, | |
40 int command, int in_data_size, int out_data_size, | |
41 void *in_data, void *out_data, TaskManager *manager, | |
42 HTask *wait_i, HTask *wait_me) { | |
43 | |
44 | |
45 int in_task_size = 0; | |
46 int out_task_size = 0; | |
47 | |
48 if (in_total_size != 0) { | |
49 in_task_size = in_total_size / in_data_size; | |
50 if (in_total_size != in_task_size * in_data_size) { | |
51 printf("mismatch of in_total_size and in_data_size\n"); | |
52 } | |
53 } | |
54 | |
55 if (out_total_size != 0) { | |
56 out_task_size = out_total_size / out_data_size; | |
57 if (out_total_size != out_task_size * out_data_size) { | |
58 printf("mismatch of out_total_size and out_data_size\n"); | |
59 } | |
60 } | |
61 | |
62 /*in, out の大きい方に合わせるのがいいかな? Taskの数は1Task分に使うデータの大きいほうを取るような仕様がいいかな*/ | |
63 int task_num = (in_task_size > out_task_size) ? in_task_size : out_task_size; | |
64 | |
65 if (task_num == 0) task_num = 1; | |
66 | |
67 /*spe分あればいいのかな?*/ | |
68 | |
69 int array_num = spe_num; | |
70 if (task_num < array_num) { | |
71 array_num = task_num; | |
72 } | |
73 | |
74 | |
75 int array_length = task_num / array_num; | |
76 int rest = task_num % array_num; | |
77 | |
78 HTaskPtr *task_array = (HTask**)manager->allocate(sizeof(HTask*)*array_num); | |
79 TaskPtr *t_exec = (Task**)manager->allocate(sizeof(Task*)*array_length*array_num); | |
80 | |
81 int index = 0; | |
82 | |
83 for (int k = 0; k < array_num; k++) { | |
84 | |
85 task_array[k] = manager->create_task_array(command,array_length,0,1,1); | |
86 t_exec[k] = 0; | |
87 | |
88 if (wait_me != 0) { | |
89 wait_me->wait_for(task_array[k]); | |
90 } | |
91 if (wait_i != 0) { | |
92 task_array[k]->wait_for(wait_i); | |
93 } | |
94 | |
95 } | |
96 | |
97 for (int j = 0; j < array_length; j++) { | |
98 for (int k = 0; k < array_num; k++) { | |
99 | |
100 t_exec[k] = task_array[k]->next_task_array(command,t_exec[k]); | |
101 t_exec[k]->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); | |
102 t_exec[k]->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); | |
103 | |
104 index++; | |
105 | |
106 } | |
107 } | |
108 | |
109 for (int k = 0; k < array_num; k++) { | |
110 task_array[k]->spawn_task_array(t_exec[k]->next()); | |
111 task_array[k]->set_cpu(SPE_ANY); | |
112 task_array[k]->spawn(); | |
113 } | |
114 | |
115 for (int k = 0; k < rest; k++) { | |
116 HTaskPtr t_exec = manager->create_task(command); | |
117 | |
118 t_exec->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); | |
119 t_exec->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); | |
120 | |
121 index++; | |
122 | |
123 if (wait_me != 0) { | |
124 wait_me->wait_for(t_exec); | |
125 } | |
126 if (wait_i != 0) { | |
127 t_exec->wait_for(wait_i); | |
128 } | |
129 | |
130 t_exec->set_cpu(SPE_ANY); | |
131 t_exec->spawn(); | |
132 | |
133 } | |
134 | |
135 | |
136 } | |
137 | |
30 void | 138 void |
31 hello_init(TaskManager *manager) | 139 hello_init(TaskManager *manager) |
32 { | 140 { |
33 | |
34 | 141 |
35 for (int i = 0; i < count; i++) { | 142 for (int i = 0; i < count; i++) { |
36 /** | 143 /** |
37 * Create Task | 144 * Create Task |
38 * create_task(Task ID); | 145 * create_task(Task ID); |
39 */ | 146 */ |
147 | |
148 | |
149 if (use_task_creater) { | |
150 | |
151 simple_task_creater(0,0,Hello,0,0,0,0,manager,0,0); | |
152 | |
153 } else { | |
40 | 154 |
41 HTask *hello = manager->create_task(Hello); | 155 HTask *hello = manager->create_task(Hello); |
42 | 156 |
43 /** | 157 /** |
44 * Select CPU | 158 * Select CPU |
52 * add_param(32bit parameter); | 166 * add_param(32bit parameter); |
53 */ | 167 */ |
54 hello->set_param(0,(memaddr)i); | 168 hello->set_param(0,(memaddr)i); |
55 | 169 |
56 hello->spawn(); | 170 hello->spawn(); |
171 } | |
57 } | 172 } |
173 | |
174 | |
58 } | 175 } |
59 | 176 |
60 int | 177 int |
61 TMmain(TaskManager *manager, int argc, char *argv[]) | 178 TMmain(TaskManager *manager, int argc, char *argv[]) |
62 { | 179 { |