annotate example/many_task/ppe/QuickSort.cc @ 1852:7e9ebc1b08b6 draft

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 21 Dec 2013 19:53:05 +0900
parents 637fa9a4105b
children f800f61a0311
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>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 SchedDefineTask(QuickSort);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
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 ) ;
934
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
8
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
9 static void
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
10 swap( Data *data, int left, int right )
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
11 {
1852
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
12 Data tmp = data[left];
934
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
13 data[left] = data[right];
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
14 data[right] = tmp;
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
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
1852
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
17 // #define USE_MEMCPY
934
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
18
467
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 220
diff changeset
19 static int
839e34d0cc3c fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 220
diff changeset
20 run(SchedTask *s, void* rbuff, void* wbuff) {
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 // copy value
1852
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
22 int begin = 0;
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
23 #if USE_SIMPLE_TASK
936
178fbcc81fda dead lock on spu/ppu mail
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 934
diff changeset
24 int end = s->read_size()/sizeof(Data);
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
25 Data *r_data = (Data*)rbuff;
934
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
26 #ifdef USE_MEMCPY
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
27 Data *w_data = (Data*)wbuff;
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
28 #endif
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
29 #else
945
9ed1c4a877ca sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 940
diff changeset
30 int end = s->get_inputSize(0)/sizeof(Data);
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
31 DataPtr r_data = (DataPtr)s->get_input(0);
934
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
32 #ifdef USE_MEMCPY
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
33 DataPtr w_data = (DataPtr)s->get_output(0);
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
34 #endif
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
35 #endif
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36
1852
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
37 //printf("[SPE] Quick: length:%d addr->%x \n",end, (int)rbuff);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
38 //printf("[PPE] Quick: data[0]: %d addr->%x\n",sizeof(r_data),r_data);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39
1852
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
40 //show_data(r_data, end);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
41 quick_sort(r_data, begin, end-1);
934
83b64b7a51bd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
42 #ifdef USE_MEMCPY
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 memcpy(w_data, r_data, sizeof(Data)*end);
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
44 #else
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
45 s->swap();
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
46 #endif
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50
1852
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
51 static void
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
52 quick_sort( Data *data, int begin, int end ) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
54 if (begin < end) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
55 int where = (begin + end) / 2;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
56 int pivot = data[where].index;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
57 data[where].index = data[begin].index;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
58 int p = begin;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
59 int i;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
60 for (i=begin+1; i<end; i++) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
61 if (data[i].index < pivot) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
62 p++;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
63 swap(data, p, i);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
64 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
65 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
66 data[begin].index = data[p].index;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
67 data[p].index = pivot;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
68
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
69 quick_sort(data, begin, p-1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
70 quick_sort(data, p+1, end); // tail call
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1851
diff changeset
71 }
1508
0e1318e7caed create sort test
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1080
diff changeset
72 }
0e1318e7caed create sort test
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1080
diff changeset
73
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1514
diff changeset
74
932
53ad3a61b40b sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
75 /* end */