annotate example/many_task/main.cc @ 1048:40cde8c1a6cd default tip

add ScaleXY (not for allExecute...)
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 08 Dec 2010 06:22:15 +0900
parents a9c7784e5dae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <stdio.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <string.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <stdlib.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include <sys/time.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "TaskManager.h"
945
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
6 #include "SchedTask.h"
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
7
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8 #include "Func.h"
220
gongo@localhost.localdomain
parents: 217
diff changeset
9 #include "sort.h"
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10
945
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
11 extern void task_init();
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
12 extern int get_split_num(int len, int num);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
13
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14
220
gongo@localhost.localdomain
parents: 217
diff changeset
15 // sort.cc
gongo@localhost.localdomain
parents: 217
diff changeset
16 extern int data_length;
gongo@localhost.localdomain
parents: 217
diff changeset
17 extern DataPtr data;
935
e54842e4d97b -a option for sort
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 934
diff changeset
18 extern int all;
e54842e4d97b -a option for sort
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 934
diff changeset
19 int all = 0;
220
gongo@localhost.localdomain
parents: 217
diff changeset
20
945
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
21 static int sort_task = SortSimple;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
22
220
gongo@localhost.localdomain
parents: 217
diff changeset
23 // 計測用
gongo@localhost.localdomain
parents: 217
diff changeset
24 static double st_time;
gongo@localhost.localdomain
parents: 217
diff changeset
25 static double ed_time;
gongo@localhost.localdomain
parents: 217
diff changeset
26
gongo@localhost.localdomain
parents: 217
diff changeset
27 static int length = 1200;
gongo@localhost.localdomain
parents: 217
diff changeset
28
gongo@localhost.localdomain
parents: 217
diff changeset
29 // prototype
400
00fe05184a02 Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 256
diff changeset
30 void TMend(TaskManager *);
220
gongo@localhost.localdomain
parents: 217
diff changeset
31
gongo@localhost.localdomain
parents: 217
diff changeset
32 static double
945
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
33 getTime()
220
gongo@localhost.localdomain
parents: 217
diff changeset
34 {
gongo@localhost.localdomain
parents: 217
diff changeset
35 struct timeval tv;
gongo@localhost.localdomain
parents: 217
diff changeset
36 gettimeofday(&tv, NULL);
gongo@localhost.localdomain
parents: 217
diff changeset
37 return tv.tv_sec + (double)tv.tv_usec*1e-6;
gongo@localhost.localdomain
parents: 217
diff changeset
38 }
256
465a871f4c07 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
39 /*
220
gongo@localhost.localdomain
parents: 217
diff changeset
40 static void
gongo@localhost.localdomain
parents: 217
diff changeset
41 show_data(void)
gongo@localhost.localdomain
parents: 217
diff changeset
42 {
gongo@localhost.localdomain
parents: 217
diff changeset
43 puts("-----------------------------------------------");
gongo@localhost.localdomain
parents: 217
diff changeset
44 for(int i = 0; i < data_length; i++) {
gongo@localhost.localdomain
parents: 217
diff changeset
45 printf("data[%02d].index = %d\n", i, data[i].index);
gongo@localhost.localdomain
parents: 217
diff changeset
46 }
gongo@localhost.localdomain
parents: 217
diff changeset
47 puts("-----------------------------------------------");
gongo@localhost.localdomain
parents: 217
diff changeset
48 }
256
465a871f4c07 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
49 */
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50
256
465a871f4c07 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
51 const char *usr_help_str = "Usage: ./sort [option]\n \
217
gongo@localhost.localdomain
parents: 109
diff changeset
52 options\n\
gongo@localhost.localdomain
parents: 109
diff changeset
53 -cpu Number of SPE used (default 1)\n\
gongo@localhost.localdomain
parents: 109
diff changeset
54 -l, --length Sorted number of data (default 1200)\n\
gongo@localhost.localdomain
parents: 109
diff changeset
55 -h, --help Print this message";
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 int
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 init(int argc, char **argv)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 for (int i = 1; argv[i]; ++i) {
217
gongo@localhost.localdomain
parents: 109
diff changeset
61 if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) {
220
gongo@localhost.localdomain
parents: 217
diff changeset
62 length = atoi(argv[++i]);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 }
935
e54842e4d97b -a option for sort
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 934
diff changeset
64 if (strcmp(argv[i], "-a") == 0 ) {
e54842e4d97b -a option for sort
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 934
diff changeset
65 all = 1;
e54842e4d97b -a option for sort
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 934
diff changeset
66 }
945
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
67 if (strcmp(argv[i], "-c") == 0 ) {
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
68 sort_task = SortCompat;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
69 }
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
70 if (strcmp(argv[i], "-s") == 0 ) {
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
71 sort_task = SortSimple;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
72 }
256
465a871f4c07 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
73
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78
945
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
79 Sort sorter;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
80
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
81 static void
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
82 check_data()
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
83 {
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
84 for(int i=0; i< sorter.data_length-1;i++) {
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
85 if (sorter.data[i].index>sorter.data[i+1].index) {
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
86 printf("Data are not sorted at %d. %d > %d \n",i, sorter.data[i].index,sorter.data[i+1].index);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
87 return;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
88 }
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
89 }
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
90 printf("Data are sorted\n");
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
91 }
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
92
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
93
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
94 static void
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
95 sort_init(SchedTask *manager, void *a, void *b)
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
96 {
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
97 sorter.cpuNum = (int)a;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
98 int length = (int)b;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
99
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
100 sorter.data = (DataPtr)manager->allocate(sizeof(Data)*length);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
101 sorter.data_length = length;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
102
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
103 sorter.split_num = get_split_num(sorter.data_length, sorter.cpuNum); // data の分割数
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
104 int half_num = sorter.split_num-1;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
105 sorter.fsort = (HTaskPtr*)manager->allocate(sizeof(HTaskPtr)*sorter.split_num);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
106 sorter.bsort = (HTaskPtr*)manager->allocate(sizeof(HTaskPtr)*half_num);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
107 memset((void*)sorter.bsort,0, sizeof(HTaskPtr)*half_num);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
108
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
109 for (int i = 0; i < length; i++) {
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
110 sorter.data[i].index = manager->get_random()%10000;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
111 sorter.data[i].ptr = i;
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
112 }
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
113
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
114 HTaskPtr restart = manager->create_task(sort_task,0,0,0,0);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
115 restart->set_param(0,(memaddr)&sorter);
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
116 restart->spawn();
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
117 }
a9c7784e5dae sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 935
diff changeset
118
220
gongo@localhost.localdomain
parents: 217
diff changeset
119 unsigned int ts, te;
gongo@localhost.localdomain
parents: 217
diff changeset
120
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
121 int
400
00fe05184a02 Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 256
diff changeset
122 TMmain(TaskManager *manager, int argc, char *argv[])
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
123 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
124 if (init(argc, argv) < 0) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
125 return -1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
126 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
127
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
128 task_init();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
129
674
bde5f13adf10 fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
130 int cpu = manager->get_cpuNum();
675
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 674
diff changeset
131
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 674
diff changeset
132 // in case of -cpu 0
674
bde5f13adf10 fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
133 if (cpu==0) cpu = 1;
932
f4d7cf77ec3d sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 675
diff changeset
134 if (1) {
f4d7cf77ec3d sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 675
diff changeset
135 HTask *dummy = manager->create_task(Dummy);
f4d7cf77ec3d sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 675
diff changeset
136 dummy->set_post(sort_init, (void*)cpu, (void*)length);
f4d7cf77ec3d sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 675
diff changeset
137 dummy->spawn();
f4d7cf77ec3d sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 675
diff changeset
138 } else {
f4d7cf77ec3d sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 675
diff changeset
139 sort_init(manager->get_schedTask(),(void*)cpu, (void*)length);
f4d7cf77ec3d sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 675
diff changeset
140 }
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
141
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
142 st_time = getTime();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
143
227
d54cbfafcb82 add sort
gongo@localhost.localdomain
parents: 220
diff changeset
144 // 全ての Task が終了した後に実行する関数をセット
220
gongo@localhost.localdomain
parents: 217
diff changeset
145 manager->set_TMend(TMend);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
146
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
147 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
148 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
149
220
gongo@localhost.localdomain
parents: 217
diff changeset
150 void
400
00fe05184a02 Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 256
diff changeset
151 TMend(TaskManager *manager)
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
152 {
220
gongo@localhost.localdomain
parents: 217
diff changeset
153 ed_time = getTime();
230
2b114977852d fix Random
gongo@localhost.localdomain
parents: 227
diff changeset
154 //show_data();
934
da657af64afd sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 932
diff changeset
155 check_data();
220
gongo@localhost.localdomain
parents: 217
diff changeset
156 printf("Time: %0.6f\n",ed_time-st_time);
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
157 }
674
bde5f13adf10 fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
158
bde5f13adf10 fix many task example (sort).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
159 /* end */