view 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 source

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include "TaskManager.h"
#include "Func.h"
#include "sort.h"
#include "prof.h"

//#define DEBUG_CHECK

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(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\
  -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]);
        }
	if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
	    printf("%s\n", help_str);
	    return -1;
	}
    }

    return 0;
}

extern void sort_init(int, int);

unsigned int ts, te;

int
TMmain(int argc, char *argv[])
{
    if (init(argc, argv) < 0) {
	return -1;
    }

    task_init();

    sort_init(manager->get_cpuNum(), length);

    st_time = getTime();
    //StartProf(ts);

    manager->set_TMend(TMend);


    return 0;
}

void
TMend(void)
{
    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
}