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