Mercurial > hg > Game > Cerium
view example/share_task/main.cc @ 252:1e697b4b7e1f draft
Document/Cerium_2009.mm
author | aaa |
---|---|
date | Tue, 02 Jun 2009 21:53:22 +0900 |
parents | 028ffc9c0375 |
children | 2c775d229cc6 |
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); int *idata; int numtask = 1; int length = DATA_NUM; char *help_str = "Usage: ./share [-task numtask] [-length data_length]\n \ -task Number of task (default 1) \n \ -length Number of data (default DATA_NUM (Func.h))"; void run_start(void) { HTaskPtr task_load; HTaskPtr task_exec; idata = (int*)manager->malloc(sizeof(int)*length); for (int i = 0; i < length; i++) { idata[i] = i; } // idata を SPU の共有領域へコピーするタスク (所謂準備的な) task_load = manager->create_task(TASK_LOAD); task_load->add_inData(idata, sizeof(int)*length); task_load->add_param(length); task_load->set_cpu(SPE_ANY); // task_load が作った領域を見ていくタスク (複数で共有して) for (int i = 0; i < numtask; i++) { task_exec = manager->create_task(TASK_EXEC); task_exec->add_param(length); task_exec->add_param(i); task_exec->add_param(ADD_NUM); task_exec->set_cpu(SPE_ANY); // dependency task_exec->wait_for(task_load); task_exec->spawn(); } // add Active Queue task_load->spawn(); } int init(int argc, char **argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-task") == 0) { numtask = atoi(argv[++i]); } if (strcmp(argv[i], "-length") == 0) { length = atoi(argv[++i]); } if (strcmp(argv[i], "--help") == 0) { printf("%s\n", help_str); return -1; } } return 0; } //---------main関数----------- int cerium_main(int argc, char *argv[]) { if (init(argc, argv) < 0) { return -1; } task_init(); run_start(); return 0; }