Mercurial > hg > Members > kono > Cerium
view example/Bulk/main.cc @ 682:80b23718df18
test code for TaskArray
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Dec 2009 18:13:46 +0900 |
parents | b976bed4e46a |
children | 9a6cb2439593 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "TaskManager.h" #include "Func.h" extern void task_init(void); static int length = DATA_NUM; static int task = 10; static int count = 10; const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ -length Number of data (default DATA_NUM (Func.h))\n\ -count Number of task (default 1)\n"; void print_data(int *data, int size, const char *title) { printf("%s ---\n", title); for (int i = 0; i < size; i++) { printf("%2d ", data[i]); } printf("\n"); } /** * タスク終了後の data1, data2 の確認 */ void twice_result(SchedTask *s, void *a, void *b) { int* data = (int*)a; print_data(data, length, "after"); free(data); } int init(int argc, char **argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-length") == 0) { length = atoi(argv[++i]); } else if (strcmp(argv[i], "-count") == 0) { task = atoi(argv[++i]); } else if (strcmp(argv[i], "-bluk") == 0) { count = atoi(argv[++i]); } } return 0; } void twice_init(TaskManager *manager) { int *data = (int*)manager->allocate(sizeof(int)*length); for (int i = 0; i < length; i++) { data[i] = i; } print_data(data, length, "before"); /** * Create Task * create_task(Task ID); */ int size = count*(SizeOfParam(2) + SizeOfData(sizeof(int)*length) + SizeOfData(sizeof(int)*length)); memaddr task_buf = (memaddr)manager->allocate(size); HTask *twice_main = manager->create_task(TaskArray, task_buf, size, 0, 0); int pos = 0; for(int i = 0;i<count;i++) { Task *t = twice_main->create_task(Twice,pos); int length2 = length/2; // 以下の順序でデータを追加する必要がある。 // length を先に指定すればsetは後からでも良い。 /** * Set 32bits parameter * add_param(32bit parameter); */ t->set_param_length(2); t->set_param(0, (memaddr)length2); t->set_param(1, (memaddr)length2); /** * Set of Input Data * add_inData(address of input data, size of input data); */ t->set_inData_length(2); t->set_inData(0,data, sizeof(int)*length2); t->set_inData(1,data+length2, sizeof(int)*length2); /** * Set of Output area * add_outData(address of output area, size of output area); */ t->set_outData_length(2); t->set_outData(0,data, sizeof(int)*length2); t->set_outData(1,data+length2, sizeof(int)*length2); pos += t->size(); // delete t; // Wao! } twice_main->set_cpu(SPE_ANY); /* * set_post() で ppe task を渡せるようにしたい */ twice_main->set_post(twice_result, (void*)data, 0); // add Active Queue twice_main->spawn(); } int TMmain(TaskManager *manager,int argc, char *argv[]) { if (init(argc, argv) < 0) { return -1; } // Task Register // ppe/task_init.cc task_init(); for (int i = 0; i < task; ++i) { twice_init(manager); } return 0; }