Mercurial > hg > Game > Cerium
annotate example/many_task/sort.cc @ 940:e01b551f25d6 draft
unknown dead lock still...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 31 Jul 2010 16:44:10 +0900 |
parents | aafa99c856a3 |
children | fc6cfaae6de7 |
rev | line source |
---|---|
227 | 1 #include "TaskManager.h" |
573 | 2 #include "SchedTask.h" |
227 | 3 #include "sort.h" |
4 #include "Func.h" | |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
5 #include <string.h> |
227 | 6 |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
7 extern void check_data(); |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
8 extern int all; // allocate task at once |
227 | 9 |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
10 static void sort_start(SchedTask *); |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
11 static int data_length; |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
12 static int cpuNum; |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
13 static int split_num; |
935 | 14 |
227 | 15 /** |
16 * 一つの block にある data の数が MAX_BLOCK_SIZE 超えないような | |
17 * len の分割数を返す | |
18 * | |
19 * @param len sort する data の総数 | |
20 * @param num 使用する SPE の数 | |
21 * | |
22 * @return data の分割数 | |
23 * | |
24 * TODO: | |
25 * len が num 以下とか考えてません | |
26 */ | |
27 static int | |
28 get_split_num(int len, int num) | |
29 { | |
30 if (len / num < MAX_BLOCK_SIZE) { | |
31 return num; | |
32 } else { | |
33 // 切り上げ | |
34 return (len + MAX_BLOCK_SIZE - 1) / MAX_BLOCK_SIZE; | |
35 } | |
36 } | |
37 | |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
38 |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
39 static HTaskPtr *fsort; |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
40 static HTaskPtr *bsort; |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
41 |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
42 static DataPtr data; |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
43 |
227 | 44 /** |
45 * btask が全て終了したら、再び sort_start を実行する | |
46 * @param d 生成された btask の数 | |
47 */ | |
935 | 48 |
49 SchedDefineTask1(RESTART, sort_restart ); | |
50 | |
51 static int | |
573 | 52 sort_restart(SchedTask *s, void *d, void *e) |
227 | 53 { |
939 | 54 // static int ccc = 0; |
227 | 55 |
938
20beb83a5a22
dead lock still remains. zombi problem?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
936
diff
changeset
|
56 // printf("restarted %d %% %d\n",ccc++,split_num); |
935 | 57 sort_start(s); |
58 return 0; | |
227 | 59 } |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
60 #ifdef USE_SIMPLE_TASK |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
61 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
62 static void |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
63 sort_start(SchedTask *manager) |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
64 { |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
65 int half_num = split_num-1; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
66 static int sort_count = split_num; // sort 完了に必要な回数 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
67 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
68 // 一つのタスクで sort する data 数 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
69 int block_num = (data_length + split_num -1)/split_num; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
70 int half_block_num = block_num/2; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
71 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
72 int last_block_num = data_length - (split_num-1)*block_num; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
73 int last_half_block_num = half_block_num+(last_block_num/2); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
74 |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
75 if (--sort_count < 0) { |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
76 return; |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
77 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
78 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
79 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
80 for (int i = 0; i < split_num-1; i++) { |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
81 fsort[i] = manager->create_task(QUICK_SORT, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
82 (memaddr)&data[i*block_num], sizeof(Data)*block_num, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
83 (memaddr)&data[i*block_num], sizeof(Data)*block_num); |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
84 if (i>0 && bsort[i-1]) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
85 fsort[i]->wait_for(bsort[i-1]); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
86 } |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
87 if (i<split_num-2 && bsort[i]) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
88 fsort[i]->wait_for(bsort[i]); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
89 } |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
90 fsort[i]->set_cpu(SPE_ANY); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
91 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
92 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
93 // 最後の block は端数なので last_block_num を使う |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
94 { |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
95 int i = split_num-1; |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
96 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
97 fsort[i] = manager->create_task(QUICK_SORT, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
98 (memaddr)&data[i*block_num], sizeof(Data)*last_block_num, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
99 (memaddr)&data[i*block_num], sizeof(Data)*last_block_num); |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
100 if (i>0 && bsort[i-1]) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
101 fsort[i]->wait_for(bsort[i-1]); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
102 } |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
103 fsort[i]->set_cpu(SPE_ANY); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
104 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
105 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
106 if (split_num > 1) { |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
107 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
108 for (int i = 0; i < half_num-1; i++) { |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
109 bsort[i] = manager->create_task(QUICK_SORT, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
110 (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*block_num, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
111 (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*block_num); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
112 bsort[i]->set_cpu(SPE_ANY); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
113 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
114 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
115 { |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
116 int i = half_num-1; |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
117 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
118 bsort[i] = manager->create_task(QUICK_SORT, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
119 (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num, |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
120 (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
121 bsort[i]->set_cpu(SPE_ANY); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
122 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
123 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
124 for (int i = 0; i < half_num; i++) { |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
125 bsort[i]->wait_for(fsort[i]); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
126 bsort[i]->wait_for(fsort[i+1]); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
127 bsort[i]->spawn(); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
128 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
129 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
130 |
935 | 131 HTaskPtr restart = manager->create_task(RESTART,0,0,0,0); |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
132 for (int i = 0; i < split_num; i++) { |
935 | 133 if (!all) restart->wait_for(fsort[i]); |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
134 fsort[i]->spawn(); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
135 } |
935 | 136 restart->spawn(); |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
137 } |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
138 |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
139 #else |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
140 |
227 | 141 static void |
674
07351a5a51c9
fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
651
diff
changeset
|
142 sort_start(SchedTask *manager) |
227 | 143 { |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
144 int half_num = split_num-1; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
145 static int sort_count = split_num; // sort 完了に必要な回数 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
146 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
147 // 一つのタスクで sort する data 数 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
148 int block_num = (data_length + split_num -1)/split_num; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
149 int half_block_num = block_num/2; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
150 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
151 int last_block_num = data_length - (split_num-1)*block_num; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
152 int last_half_block_num = half_block_num+(last_block_num/2); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
153 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
154 |
227 | 155 if (--sort_count < 0) { |
156 return; | |
157 } | |
158 | |
159 | |
160 for (int i = 0; i < split_num-1; i++) { | |
161 fsort[i] = manager->create_task(QUICK_SORT); | |
162 fsort[i]->add_inData(&data[i*block_num], sizeof(Data)*block_num); | |
163 fsort[i]->add_outData(&data[i*block_num], sizeof(Data)*block_num); | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
164 fsort[i]->set_param(0,(memaddr)block_num); |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
165 if (i>0 && bsort[i-1]) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
166 fsort[i]->wait_for(bsort[i-1]); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
167 } |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
168 if (i<split_num-2 && bsort[i]) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
169 fsort[i]->wait_for(bsort[i]); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
170 } |
227 | 171 fsort[i]->set_cpu(SPE_ANY); |
172 } | |
173 | |
174 // 最後の block は端数なので last_block_num を使う | |
175 { | |
176 int i = split_num-1; | |
177 | |
178 fsort[i] = manager->create_task(QUICK_SORT); | |
179 fsort[i]->add_inData(&data[i*block_num], sizeof(Data)*last_block_num); | |
180 fsort[i]->add_outData(&data[i*block_num], sizeof(Data)*last_block_num); | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
181 fsort[i]->set_param(0,(memaddr)last_block_num); |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
182 if (i>0 && bsort[i-1]) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
183 fsort[i]->wait_for(bsort[i-1]); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
184 } |
227 | 185 fsort[i]->set_cpu(SPE_ANY); |
186 } | |
187 | |
188 if (split_num > 1) { | |
189 HTaskPtr bsort[half_num]; | |
190 | |
191 for (int i = 0; i < half_num-1; i++) { | |
192 bsort[i] = manager->create_task(QUICK_SORT); | |
193 bsort[i]->add_inData(&data[i*block_num+half_block_num], | |
194 sizeof(Data)*block_num); | |
195 bsort[i]->add_outData(&data[i*block_num+half_block_num], | |
196 sizeof(Data)*block_num); | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
197 bsort[i]->set_param(0,(memaddr)block_num); |
227 | 198 bsort[i]->set_cpu(SPE_ANY); |
199 } | |
200 | |
201 { | |
202 int i = half_num-1; | |
203 | |
204 bsort[i] = manager->create_task(QUICK_SORT); | |
205 bsort[i]->add_inData(&data[i*block_num+half_block_num], | |
206 sizeof(Data)*last_half_block_num); | |
207 bsort[i]->add_outData(&data[i*block_num+half_block_num], | |
208 sizeof(Data)*last_half_block_num); | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
209 bsort[i]->set_param(0,(memaddr)last_half_block_num); |
227 | 210 bsort[i]->set_cpu(SPE_ANY); |
211 } | |
212 | |
213 for (int i = 0; i < half_num; i++) { | |
214 bsort[i]->wait_for(fsort[i]); | |
215 bsort[i]->wait_for(fsort[i+1]); | |
216 bsort[i]->spawn(); | |
217 } | |
218 } | |
219 | |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
220 HTaskPtr restart = manager->create_task(RESTART,0,0,0,0); |
227 | 221 for (int i = 0; i < split_num; i++) { |
935 | 222 if (!all) restart->wait_for(fsort[i]); |
227 | 223 fsort[i]->spawn(); |
224 } | |
935 | 225 restart->spawn(); |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
226 } |
935 | 227 |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
674
diff
changeset
|
228 #endif |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
229 |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
230 void check_data() |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
231 { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
232 for(int i=0; i< data_length-1;i++) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
233 if (data[i].index>data[i+1].index) { |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
234 printf("Data are not sorted at %d. %d > %d \n",i, data[i].index,data[i+1].index); |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
235 return; |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
236 } |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
237 } |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
238 printf("Data are sorted\n"); |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
239 } |
227 | 240 |
935 | 241 |
227 | 242 void |
674
07351a5a51c9
fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
651
diff
changeset
|
243 sort_init(SchedTask *manager, void *a, void *b) |
227 | 244 { |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
245 cpuNum = (int)a; |
674
07351a5a51c9
fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
651
diff
changeset
|
246 int length = (int)b; |
400 | 247 |
227 | 248 data = (DataPtr)manager->allocate(sizeof(Data)*length); |
249 data_length = length; | |
250 | |
935 | 251 split_num = get_split_num(data_length, cpuNum); // data の分割数 |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
252 int half_num = split_num-1; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
253 fsort = (HTaskPtr*)manager->allocate(sizeof(HTaskPtr)*split_num); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
254 bsort = (HTaskPtr*)manager->allocate(sizeof(HTaskPtr)*half_num); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
255 memset((void*)bsort,0, sizeof(HTaskPtr)*half_num); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
256 |
227 | 257 for (int i = 0; i < length; i++) { |
230 | 258 data[i].index = manager->get_random()%10000; |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
259 data[i].ptr = i; |
227 | 260 } |
261 | |
674
07351a5a51c9
fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
651
diff
changeset
|
262 sort_start(manager); |
227 | 263 } |
400 | 264 |
651 | 265 /* end */ |