annotate example/many_task/main.cc @ 292:2369f477ffbe draft

Document/Cerium_2009.mm
author aaa
date Fri, 05 Jun 2009 18:53:42 +0900
parents 2c775d229cc6
children 984e7890db0c
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 <stdio.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <string.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <stdlib.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include <sys/time.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "TaskManager.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 #include "Func.h"
220
gongo@localhost.localdomain
parents: 217
diff changeset
7 #include "sort.h"
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 extern void task_init(void);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10
220
gongo@localhost.localdomain
parents: 217
diff changeset
11 // sort.cc
gongo@localhost.localdomain
parents: 217
diff changeset
12 extern int data_length;
gongo@localhost.localdomain
parents: 217
diff changeset
13 extern DataPtr data;
gongo@localhost.localdomain
parents: 217
diff changeset
14
gongo@localhost.localdomain
parents: 217
diff changeset
15 // 計測用
gongo@localhost.localdomain
parents: 217
diff changeset
16 static double st_time;
gongo@localhost.localdomain
parents: 217
diff changeset
17 static double ed_time;
gongo@localhost.localdomain
parents: 217
diff changeset
18
gongo@localhost.localdomain
parents: 217
diff changeset
19 static int length = 1200;
gongo@localhost.localdomain
parents: 217
diff changeset
20
gongo@localhost.localdomain
parents: 217
diff changeset
21 // prototype
gongo@localhost.localdomain
parents: 217
diff changeset
22 void TMend(void);
gongo@localhost.localdomain
parents: 217
diff changeset
23
gongo@localhost.localdomain
parents: 217
diff changeset
24 static double
gongo@localhost.localdomain
parents: 217
diff changeset
25 getTime(void)
gongo@localhost.localdomain
parents: 217
diff changeset
26 {
gongo@localhost.localdomain
parents: 217
diff changeset
27 struct timeval tv;
gongo@localhost.localdomain
parents: 217
diff changeset
28 gettimeofday(&tv, NULL);
gongo@localhost.localdomain
parents: 217
diff changeset
29 return tv.tv_sec + (double)tv.tv_usec*1e-6;
gongo@localhost.localdomain
parents: 217
diff changeset
30 }
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
31 /*
220
gongo@localhost.localdomain
parents: 217
diff changeset
32 static void
gongo@localhost.localdomain
parents: 217
diff changeset
33 show_data(void)
gongo@localhost.localdomain
parents: 217
diff changeset
34 {
gongo@localhost.localdomain
parents: 217
diff changeset
35 puts("-----------------------------------------------");
gongo@localhost.localdomain
parents: 217
diff changeset
36 for(int i = 0; i < data_length; i++) {
gongo@localhost.localdomain
parents: 217
diff changeset
37 printf("data[%02d].index = %d\n", i, data[i].index);
gongo@localhost.localdomain
parents: 217
diff changeset
38 }
gongo@localhost.localdomain
parents: 217
diff changeset
39 puts("-----------------------------------------------");
gongo@localhost.localdomain
parents: 217
diff changeset
40 }
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
41 */
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
43 const char *usr_help_str = "Usage: ./sort [option]\n \
217
gongo@localhost.localdomain
parents: 109
diff changeset
44 options\n\
gongo@localhost.localdomain
parents: 109
diff changeset
45 -cpu Number of SPE used (default 1)\n\
gongo@localhost.localdomain
parents: 109
diff changeset
46 -l, --length Sorted number of data (default 1200)\n\
gongo@localhost.localdomain
parents: 109
diff changeset
47 -h, --help Print this message";
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 init(int argc, char **argv)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 for (int i = 1; argv[i]; ++i) {
217
gongo@localhost.localdomain
parents: 109
diff changeset
53 if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) {
220
gongo@localhost.localdomain
parents: 217
diff changeset
54 length = atoi(argv[++i]);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 }
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 230
diff changeset
56
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61
220
gongo@localhost.localdomain
parents: 217
diff changeset
62 extern void sort_init(int, int);
gongo@localhost.localdomain
parents: 217
diff changeset
63
gongo@localhost.localdomain
parents: 217
diff changeset
64 unsigned int ts, te;
gongo@localhost.localdomain
parents: 217
diff changeset
65
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 int
220
gongo@localhost.localdomain
parents: 217
diff changeset
67 TMmain(int argc, char *argv[])
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 if (init(argc, argv) < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 return -1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73 task_init();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74
220
gongo@localhost.localdomain
parents: 217
diff changeset
75 sort_init(manager->get_cpuNum(), length);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 st_time = getTime();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78
227
e7faaf516be1 add sort
gongo@localhost.localdomain
parents: 220
diff changeset
79 // 全ての Task が終了した後に実行する関数をセット
220
gongo@localhost.localdomain
parents: 217
diff changeset
80 manager->set_TMend(TMend);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84
220
gongo@localhost.localdomain
parents: 217
diff changeset
85 void
gongo@localhost.localdomain
parents: 217
diff changeset
86 TMend(void)
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 {
220
gongo@localhost.localdomain
parents: 217
diff changeset
88 ed_time = getTime();
230
56314060907f fix Random
gongo@localhost.localdomain
parents: 227
diff changeset
89 //show_data();
220
gongo@localhost.localdomain
parents: 217
diff changeset
90 printf("Time: %0.6f\n",ed_time-st_time);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91 }