comparison example/many_task/main.cc @ 220:305ac1897c50 draft

fix
author gongo@localhost.localdomain
date Mon, 09 Feb 2009 21:58:45 +0900
parents bfdd037aee21
children e7faaf516be1
comparison
equal deleted inserted replaced
219:335ea3665fcd 220:305ac1897c50
2 #include <string.h> 2 #include <string.h>
3 #include <stdlib.h> 3 #include <stdlib.h>
4 #include <sys/time.h> 4 #include <sys/time.h>
5 #include "TaskManager.h" 5 #include "TaskManager.h"
6 #include "Func.h" 6 #include "Func.h"
7 #include "sort.h"
8 #include "prof.h"
9
10 //#define DEBUG_CHECK
7 11
8 extern void task_init(void); 12 extern void task_init(void);
9 13
10 int data_size = 1200; 14 // sort.cc
11 15 extern int data_length;
12 double getTime(); 16 extern DataPtr data;
17
18 // 計測用
19 static double st_time;
20 static double ed_time;
21
22 static int length = 1200;
23
24 // prototype
25 void TMend(void);
26
27 static double
28 getTime(void)
29 {
30 struct timeval tv;
31 gettimeofday(&tv, NULL);
32 return tv.tv_sec + (double)tv.tv_usec*1e-6;
33 }
34
35 static void
36 show_data(void)
37 {
38 #if defined(DEBUG_CHECK)
39 for(int i = 0; i < data_length; i++) {
40 printf("%d\n", data[i].index);
41 }
42 #else
43 puts("-----------------------------------------------");
44 for(int i = 0; i < data_length; i++) {
45 printf("data[%02d].index = %d\n", i, data[i].index);
46 }
47 puts("-----------------------------------------------");
48 #endif
49 }
13 50
14 const char *help_str = "Usage: ./sort [option]\n \ 51 const char *help_str = "Usage: ./sort [option]\n \
15 options\n\ 52 options\n\
16 -cpu Number of SPE used (default 1)\n\ 53 -cpu Number of SPE used (default 1)\n\
17 -l, --length Sorted number of data (default 1200)\n\ 54 -l, --length Sorted number of data (default 1200)\n\
20 int 57 int
21 init(int argc, char **argv) 58 init(int argc, char **argv)
22 { 59 {
23 for (int i = 1; argv[i]; ++i) { 60 for (int i = 1; argv[i]; ++i) {
24 if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) { 61 if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) {
25 data_size = atoi(argv[++i]); 62 length = atoi(argv[++i]);
26 } 63 }
27 if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { 64 if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
28 printf("%s\n", help_str); 65 printf("%s\n", help_str);
29 return -1; 66 return -1;
30 } 67 }
31 } 68 }
32 69
33 return 0; 70 return 0;
34 } 71 }
35 72
73 extern void sort_init(int, int);
74
75 unsigned int ts, te;
76
36 int 77 int
37 cerium_main(int argc, char *argv[]) 78 TMmain(int argc, char *argv[])
38 { 79 {
39 // 計測用
40 double st_time, ed_time;
41 HTask *runLoop;
42
43 if (init(argc, argv) < 0) { 80 if (init(argc, argv) < 0) {
44 return -1; 81 return -1;
45 } 82 }
46 83
47 task_init(); 84 task_init();
48 85
49 runLoop = manager->create_task(TASK_MAIN); 86 sort_init(manager->get_cpuNum(), length);
50 runLoop->add_param(6);
51 runLoop->add_param(data_size);
52 87
53 runLoop->spawn();
54 // Start
55 st_time = getTime(); 88 st_time = getTime();
56 //manager->run(); 89 //StartProf(ts);
57 //ed_time = getTime();
58 90
59 //printf("Time: %0.6f\n",ed_time-st_time); 91 manager->set_TMend(TMend);
60 92
61 //delete manager;
62 93
63 FINISH:
64 return 0; 94 return 0;
65 } 95 }
66 96
67 double getTime() 97 void
98 TMend(void)
68 { 99 {
69 struct timeval tv; 100 ed_time = getTime();
70 gettimeofday(&tv, NULL); 101 //show_data();
71 return tv.tv_sec + (double)tv.tv_usec*1e-6; 102 #if !defined(DEBUG_CHECK)
103 //StopProf(te, ts);
104
105 //unsigned tmps, tmpe;
106
107 // profile のコスト計算
108 //StartProf(tmps);
109 //StopProf(tmpe, tmps);
110
111 //PrintProf((te - tmpe));
112 printf("Time: %0.6f\n",ed_time-st_time);
113 #endif
72 } 114 }