Mercurial > hg > Game > Cerium
view TaskManager/test/UtilizationTest/main.cc @ 1697:ef1099c41449 draft
UtilizationTest
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 04 Oct 2013 16:41:23 +0900 |
parents | |
children | 7673e2ad2623 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #include "TaskManager.h" #include "Func.h" extern void task_init(void); static int task = 1; static int length = DATA_NUM; const char *usr_help_str = "Usage: ./multiply \n"; static int print_flag = 0; void TMend(TaskManager *); float *A,*B,*C; static double st_time = 0 ; static double ed_time = 0; static double getTime() { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + (double)tv.tv_usec*1e-6; } static void check_data() { for(int i=0; i<length;i++) { if (A[i]*B[i]!=C[i]) { printf("Multiplication went wrong.\n"); return; } } printf("Multiplication was succeeded.\n"); return; } static void print_result() { printf("---\n"); if(print_flag == 1) { for (int i =0;i<length;i++) { printf("%f * %f = %f \n",A[i],B[i],C[i]); } } printf("---\n"); } void init(int args, char *argv[]) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) { length = atoi(argv[++i]); } else if (strcmp(argv[i], "-t") == 0) { task = atoi(argv[++i]); } else if (strcmp(argv[i], "-print") == 0) { print_flag = 1; } } } void multi_init(TaskManager *manager) { A = new float[length]; B = new float[length]; C = new float[length]; for(int i=0; i<length; i++) { A[i]=(float)(i+1000); B[i]=(float)(i+1)/10.f; } HTask *multiply = manager->create_task(MULTIPLY_TASK); multiply->set_cpu((CPU_TYPE)((int)SPE_0)); multiply->set_inData(0,(memaddr)A, sizeof(float)*length); multiply->set_inData(1,(memaddr)B, sizeof(float)*length); multiply->set_outData(0,(memaddr)C, sizeof(float)*length); multiply->spawn(); HTask* previous = multiply; for(int i=1;i<4;i++) { multiply = manager->create_task(MULTIPLY_TASK); multiply->set_cpu((CPU_TYPE)((int)SPE_0+i)); multiply->set_inData(0,(memaddr)A, sizeof(float)*length); multiply->set_inData(1,(memaddr)B, sizeof(float)*length); multiply->set_outData(0,(memaddr)C, sizeof(float)*length); multiply->wait_for(previous); multiply->spawn(); previous = multiply; } // // HTask* second_multiply = manager->create_task(MULTIPLY_TASK); // // second_multiply->set_cpu(SPE_1); // // second_multiply->set_inData(0,(memaddr)A, sizeof(float)*length); // // second_multiply->set_inData(1,(memaddr)B, sizeof(float)*length); // // second_multiply->set_outData(0,(memaddr)C, sizeof(float)*length); // // second_multiply->wait_for(multiply); // second_multiply->spawn(); // multiply = manager->create_task(MULTIPLY_TASK); // multiply->set_cpu(SPE_2); // multiply->set_inData(0,(memaddr)A, sizeof(float)*length); // multiply->set_inData(1,(memaddr)B, sizeof(float)*length); // multiply->set_outData(0,(memaddr)C, sizeof(float)*length); // multiply->spawn(); } int TMmain(TaskManager *manager,int argc, char *argv[]) { init(argc, argv); // Task Register task_init(); for (int i = 0; i < task; ++i) { multi_init(manager); } st_time = getTime(); manager->set_TMend(TMend); return 0; } void TMend(TaskManager *manager) { ed_time = getTime(); print_result(); printf("Time: %0.6f\n",ed_time-st_time); check_data(); delete A; delete B; delete C; }