Mercurial > hg > Game > Cerium
annotate example/share_task/main.cc @ 839:1001c4bea1a0 draft
if unnecessary
author | Yutaka_Kinjyo |
---|---|
date | Fri, 28 May 2010 03:24:52 +0900 |
parents | 94d82f2c842f |
children | f40558ec00a8 |
rev | line source |
---|---|
109 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
5 #include "Func.h" | |
6 | |
400 | 7 extern void task_init(); |
109 | 8 |
9 int *idata; | |
10 int numtask = 1; | |
11 int length = DATA_NUM; | |
12 | |
256 | 13 const char *usr_help_str = "Usage: ./share [-task numtask] [-length data_length]\n \ |
109 | 14 -task Number of task (default 1) \n \ |
15 -length Number of data (default DATA_NUM (Func.h))"; | |
16 | |
17 void | |
400 | 18 run_start(TaskManager *manager) |
109 | 19 { |
20 HTaskPtr task_load; | |
21 HTaskPtr task_exec; | |
22 | |
256 | 23 idata = (int*)manager->allocate(sizeof(int)*length); |
109 | 24 for (int i = 0; i < length; i++) { |
25 idata[i] = i; | |
26 } | |
27 | |
298 | 28 // idata を SPU の共有領域へコピーするタスク (所謂準備的な) |
109 | 29 task_load = manager->create_task(TASK_LOAD); |
30 task_load->add_inData(idata, sizeof(int)*length); | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
31 task_load->set_param(0,(memaddr)length); |
109 | 32 task_load->set_cpu(SPE_ANY); |
33 | |
298 | 34 // task_load が作った領域を見ていくタスク (複数で共有して) |
109 | 35 for (int i = 0; i < numtask; i++) { |
36 task_exec = manager->create_task(TASK_EXEC); | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
37 task_exec->set_param(0,(memaddr)length); |
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
38 task_exec->set_param(1,(memaddr)i); |
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
39 task_exec->set_param(2,(memaddr)ADD_NUM); |
109 | 40 task_exec->set_cpu(SPE_ANY); |
41 | |
42 // dependency | |
43 task_exec->wait_for(task_load); | |
44 task_exec->spawn(); | |
45 } | |
46 | |
47 // add Active Queue | |
48 task_load->spawn(); | |
49 } | |
50 | |
51 int | |
52 init(int argc, char **argv) | |
53 { | |
54 for (int i = 1; argv[i]; ++i) { | |
55 if (strcmp(argv[i], "-task") == 0) { | |
56 numtask = atoi(argv[++i]); | |
57 } | |
58 if (strcmp(argv[i], "-length") == 0) { | |
59 length = atoi(argv[++i]); | |
60 } | |
61 } | |
62 | |
63 return 0; | |
64 } | |
65 | |
298 | 66 //---------main関数----------- |
109 | 67 int |
400 | 68 TMmain(TaskManager *manager, int argc, char *argv[]) |
109 | 69 { |
70 | |
71 if (init(argc, argv) < 0) { | |
72 return -1; | |
73 } | |
74 | |
75 task_init(); | |
76 | |
400 | 77 run_start(manager); |
109 | 78 |
79 return 0; | |
80 } |