annotate example/many_task/spe/QuickSort.cc @ 725:3a97fdd53a8e draft

Light data load fix (general load routine)
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 19 Dec 2009 15:02:43 +0900
parents 0e91ddaad798
children 53ad3a61b40b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include "QuickSort.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <stdio.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <string.h>
233
gongo@localhost.localdomain
parents: 230
diff changeset
4 #include "SpeProfile.h"
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 SchedDefineTask(QuickSort);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7
467
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
8 static void bubble_sort(DataPtr data, int begin, int end);
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
9 static void quick_sort(DataPtr data, int begin, int end);
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
10
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
11 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: 356
diff changeset
12
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
13 static int
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
14 run(SchedTask *smanager, void* rbuff, void* wbuff) {
220
gongo@localhost.localdomain
parents: 109
diff changeset
15 int begin = 0;
626
0e91ddaad798 64bit mode compatibility on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 467
diff changeset
16 int end = (long)smanager->get_param(0);
316
f92cd4e563dc run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 310
diff changeset
17 DataPtr r_data = (DataPtr)smanager->get_input(0);
f92cd4e563dc run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 310
diff changeset
18 DataPtr w_data = (DataPtr)smanager->get_output(0);
233
gongo@localhost.localdomain
parents: 230
diff changeset
19 //SpeProfile *prof = new SpeProfile;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20
233
gongo@localhost.localdomain
parents: 230
diff changeset
21 //prof->ProfStart();
467
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
22 if (0)
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
23 bubble_sort(r_data, begin, end-1);
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
24 else
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
25 quick_sort(r_data, begin, end-1);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 memcpy(w_data, r_data, sizeof(Data)*end);
233
gongo@localhost.localdomain
parents: 230
diff changeset
27 //prof->ProfStop();
gongo@localhost.localdomain
parents: 230
diff changeset
28 //prof->ProfPrint();
220
gongo@localhost.localdomain
parents: 109
diff changeset
29
233
gongo@localhost.localdomain
parents: 230
diff changeset
30 //delete prof;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33
467
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
34 static void
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
35 bubble_sort(DataPtr data, int begin, int end)
220
gongo@localhost.localdomain
parents: 109
diff changeset
36 {
gongo@localhost.localdomain
parents: 109
diff changeset
37 for (int i = 0; i < end; i++) {
gongo@localhost.localdomain
parents: 109
diff changeset
38 for (int j = end; j > i; j--) {
gongo@localhost.localdomain
parents: 109
diff changeset
39 if (data[j].index < data[j-1].index) {
gongo@localhost.localdomain
parents: 109
diff changeset
40 swap(data, j, j-1);
gongo@localhost.localdomain
parents: 109
diff changeset
41 }
gongo@localhost.localdomain
parents: 109
diff changeset
42 }
gongo@localhost.localdomain
parents: 109
diff changeset
43 }
gongo@localhost.localdomain
parents: 109
diff changeset
44 }
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45
467
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
46
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
47 static void
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
48 quick_sort(DataPtr data, int begin, int end)
220
gongo@localhost.localdomain
parents: 109
diff changeset
49 {
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 if (begin < end) {
220
gongo@localhost.localdomain
parents: 109
diff changeset
51
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 int where = (begin + end) / 2;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53 int pivot = data[where].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 data[where].index = data[begin].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 int p = begin;
220
gongo@localhost.localdomain
parents: 109
diff changeset
56
gongo@localhost.localdomain
parents: 109
diff changeset
57 for (int i = begin+1; i <= end; i++) {
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 if (data[i].index < pivot) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 p++;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 swap(data, p, i);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62 }
220
gongo@localhost.localdomain
parents: 109
diff changeset
63
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 data[begin].index = data[p].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65 data[p].index = pivot;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 quick_sort(data, begin, p-1);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 quick_sort(data, p+1, end);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71
467
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
72
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
73 static void
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
74 swap(Data *data, int left, int right)
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 {
220
gongo@localhost.localdomain
parents: 109
diff changeset
76 int tmp = data[left].index;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 data[left].index = data[right].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 data[right].index = tmp;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 }
467
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
80
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 356
diff changeset
81 /* end */