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
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 ) ;
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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 // copy value
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
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
gongo@localhost.localdomain
parents: 109
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 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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 //printf("[PPE] Quick: length:%d addr->%x \n",end, (int*)rbuff);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20 //printf("[PPE] Quick: data[0]: %d addr->%x\n",sizeof(r_data),r_data);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22 //show_data(r_data, end);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 quick_sort(r_data, begin, end-1);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 memcpy(w_data, r_data, sizeof(Data)*end);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 if (begin < end) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33 int where = (begin + end) / 2;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 int pivot = data[where].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 data[where].index = data[begin].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 int p = begin;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 int i;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 for (i=begin+1; i<=end; i++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 if (data[i].index < pivot) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 p++;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 swap(data, p, i);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44 data[begin].index = data[p].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45 data[p].index = pivot;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 quick_sort(data, begin, p-1);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 quick_sort(data, p+1, end);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 int tmp = data[left].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 data[left].index = data[right].index;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 data[right].index = tmp;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 }