Mercurial > hg > Members > kono > Cerium
view example/many_task/main.cc @ 675:45ddb28c592d
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Dec 2009 01:20:41 +0900 |
parents | bde5f13adf10 |
children | f4d7cf77ec3d |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/time.h> #include "TaskManager.h" #include "Func.h" #include "sort.h" extern void task_init(void); // sort.cc extern int data_length; extern DataPtr data; // 計測用 static double st_time; static double ed_time; static int length = 1200; // prototype void TMend(TaskManager *); 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) { puts("-----------------------------------------------"); for(int i = 0; i < data_length; i++) { printf("data[%02d].index = %d\n", i, data[i].index); } puts("-----------------------------------------------"); } */ const char *usr_help_str = "Usage: ./sort [option]\n \ options\n\ -cpu Number of SPE used (default 1)\n\ -l, --length Sorted number of data (default 1200)\n\ -h, --help Print this message"; int init(int argc, char **argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) { length = atoi(argv[++i]); } } return 0; } unsigned int ts, te; int TMmain(TaskManager *manager, int argc, char *argv[]) { if (init(argc, argv) < 0) { return -1; } task_init(); HTask *dummy = manager->create_task(Dummy); int cpu = manager->get_cpuNum(); // in case of -cpu 0 if (cpu==0) cpu = 1; dummy->set_post(sort_init, (void*)cpu, (void*)length); dummy->spawn(); st_time = getTime(); // 全ての Task が終了した後に実行する関数をセット manager->set_TMend(TMend); return 0; } void TMend(TaskManager *manager) { ed_time = getTime(); //show_data(); printf("Time: %0.6f\n",ed_time-st_time); } /* end */