diff 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
line wrap: on
line diff
--- a/example/many_task/main.cc	Mon Feb 09 00:12:40 2009 +0900
+++ b/example/many_task/main.cc	Mon Feb 09 21:58:45 2009 +0900
@@ -4,12 +4,49 @@
 #include <sys/time.h>
 #include "TaskManager.h"
 #include "Func.h"
+#include "sort.h"
+#include "prof.h"
+
+//#define DEBUG_CHECK
 
 extern void task_init(void);
 
-int data_size = 1200;
- 
-double getTime();
+// sort.cc
+extern int data_length;
+extern DataPtr data;
+
+// 計測用
+static double st_time;
+static double ed_time;
+
+static int length = 1200;
+
+// prototype
+void TMend(void);
+
+static double
+getTime(void)
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return tv.tv_sec + (double)tv.tv_usec*1e-6;
+}
+
+static void
+show_data(void)
+{
+#if defined(DEBUG_CHECK)
+    for(int i = 0; i < data_length; i++) {
+	printf("%d\n", data[i].index);
+    }
+#else
+    puts("-----------------------------------------------");
+    for(int i = 0; i < data_length; i++) {
+	printf("data[%02d].index = %d\n", i, data[i].index);
+    }
+    puts("-----------------------------------------------");
+#endif
+}
 
 const char *help_str = "Usage: ./sort [option]\n \
 options\n\
@@ -22,7 +59,7 @@
 {
     for (int i = 1; argv[i]; ++i) {
         if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) {
-            data_size = atoi(argv[++i]);
+            length = atoi(argv[++i]);
         }
 	if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
 	    printf("%s\n", help_str);
@@ -33,40 +70,45 @@
     return 0;
 }
 
+extern void sort_init(int, int);
+
+unsigned int ts, te;
+
 int
-cerium_main(int argc, char *argv[])
+TMmain(int argc, char *argv[])
 {
-    // 計測用
-    double st_time, ed_time;	
-    HTask *runLoop;
-
     if (init(argc, argv) < 0) {
 	return -1;
     }
 
     task_init();
 
-    runLoop = manager->create_task(TASK_MAIN);
-    runLoop->add_param(6);
-    runLoop->add_param(data_size);
+    sort_init(manager->get_cpuNum(), length);
 
-    runLoop->spawn();
-    // Start
     st_time = getTime();
-    //manager->run();
-    //ed_time = getTime();
+    //StartProf(ts);
 
-    //printf("Time: %0.6f\n",ed_time-st_time);
+    manager->set_TMend(TMend);
 
-    //delete manager;
 
-FINISH:
     return 0;
 }
 
-double getTime()
+void
+TMend(void)
 {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return tv.tv_sec + (double)tv.tv_usec*1e-6;
+    ed_time = getTime();
+    //show_data();
+#if !defined(DEBUG_CHECK)
+    //StopProf(te, ts);
+
+    //unsigned tmps, tmpe;
+    
+    // profile のコスト計算
+    //StartProf(tmps);
+    //StopProf(tmpe, tmps);
+ 
+    //PrintProf((te - tmpe));
+    printf("Time: %0.6f\n",ed_time-st_time);
+#endif
 }