Mercurial > hg > Game > Cerium
annotate example/many_task/ppe/QuickSort.cc @ 467:839e34d0cc3c draft
fix all examples. test_render is not working now.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 01 Oct 2009 19:25:25 +0900 |
parents | 305ac1897c50 |
children | 94d82f2c842f |
rev | line source |
---|---|
109 | 1 #include "QuickSort.h" |
2 #include <stdio.h> | |
3 #include <string.h> | |
4 | |
5 SchedDefineTask(QuickSort); | |
6 | |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
7 static void quick_sort( Data *data, int begin, int end ) ; |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
8 static void swap( Data *data, int left, int right ); |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
9 |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
10 static int |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
11 run(SchedTask *s, void* rbuff, void* wbuff) { |
109 | 12 // copy value |
13 int begin = 0; | |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
14 int end = s->get_param(0); |
220 | 15 |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
16 Data *r_data = (Data*)s->get_input(rbuff, 0); |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
17 Data *w_data = (Data*)s->get_output(wbuff, 0); |
109 | 18 |
19 //printf("[PPE] Quick: length:%d addr->%x \n",end, (int*)rbuff); | |
20 //printf("[PPE] Quick: data[0]: %d addr->%x\n",sizeof(r_data),r_data); | |
21 | |
22 //show_data(r_data, end); | |
23 quick_sort(r_data, begin, end-1); | |
24 memcpy(w_data, r_data, sizeof(Data)*end); | |
25 | |
26 return 0; | |
27 } | |
28 | |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
29 static void |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
30 quick_sort( Data *data, int begin, int end ) { |
109 | 31 |
32 if (begin < end) { | |
33 int where = (begin + end) / 2; | |
34 int pivot = data[where].index; | |
35 data[where].index = data[begin].index; | |
36 int p = begin; | |
37 int i; | |
38 for (i=begin+1; i<=end; i++) { | |
39 if (data[i].index < pivot) { | |
40 p++; | |
41 swap(data, p, i); | |
42 } | |
43 } | |
44 data[begin].index = data[p].index; | |
45 data[p].index = pivot; | |
46 | |
47 quick_sort(data, begin, p-1); | |
48 quick_sort(data, p+1, end); | |
49 } | |
50 } | |
51 | |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
52 static void |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
53 swap( Data *data, int left, int right ) |
109 | 54 { |
55 int tmp = data[left].index; | |
56 data[left].index = data[right].index; | |
57 data[right].index = tmp; | |
58 } |