annotate example/many_task/main.cc @ 109:028ffc9c0375 draft

Cerium cvs version
author gongo@gendarme.local
date Wed, 12 Nov 2008 17:39:33 +0900
parents
children bfdd037aee21
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"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8 extern void task_init(void);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10 int data_size = 1200;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 double getTime();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 char *help_str = "Usage: ./sort [-cpu spe_num] [-length data_length]\n \
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 -cpu Number of SPE used (default 1) \n \
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16 -length Sorted number of data (default 1200)";
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 init(int argc, char **argv)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 for (int i = 1; argv[i]; ++i) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22 if (strcmp(argv[i], "-length") == 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 data_size = atoi(argv[++i]);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 if (strcmp(argv[i], "--help") == 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 printf("%s\n", help_str);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 return -1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30
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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 main(int argc, char *argv[])
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 // 計測用
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 double st_time, ed_time;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 HTask *runLoop;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 if (init(argc, argv) < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 return -1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45 task_init();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 runLoop = manager->create_task(TASK_MAIN);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 printf("main spenum: %d\n",spenum);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 runLoop->add_param(spenum);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 runLoop->add_param(data_size);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 runLoop->spawn();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53 // Start
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 st_time = getTime();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 manager->run();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 ed_time = getTime();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 printf("Time: %0.6f\n",ed_time-st_time);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 delete manager;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62 FINISH:
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 double getTime()
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 struct timeval tv;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 gettimeofday(&tv, NULL);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 return tv.tv_sec + (double)tv.tv_usec*1e-6;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 }