109
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include "TaskManager.h"
|
|
5 #include "Func.h"
|
|
6
|
|
7 extern void task_init(void);
|
|
8
|
|
9 int *idata;
|
|
10 int numtask = 1;
|
|
11 int length = DATA_NUM;
|
|
12
|
|
13 char *help_str = "Usage: ./share [-task numtask] [-length data_length]\n \
|
|
14 -task Number of task (default 1) \n \
|
|
15 -length Number of data (default DATA_NUM (Func.h))";
|
|
16
|
|
17 void
|
|
18 run_start(void)
|
|
19 {
|
|
20 HTaskPtr task_load;
|
|
21 HTaskPtr task_exec;
|
|
22
|
|
23 idata = (int*)manager->malloc(sizeof(int)*length);
|
|
24 for (int i = 0; i < length; i++) {
|
|
25 idata[i] = i;
|
|
26 }
|
|
27
|
|
28 // idata を SPU の共有領域へコピーするタスク (所謂準備的な)
|
|
29 task_load = manager->create_task(TASK_LOAD);
|
|
30 task_load->add_inData(idata, sizeof(int)*length);
|
|
31 task_load->add_param(length);
|
|
32 task_load->set_cpu(SPE_ANY);
|
|
33
|
|
34 // task_load が作った領域を見ていくタスク (複数で共有して)
|
|
35 for (int i = 0; i < numtask; i++) {
|
|
36 task_exec = manager->create_task(TASK_EXEC);
|
|
37 task_exec->add_param(length);
|
|
38 task_exec->add_param(i);
|
|
39 task_exec->add_param(ADD_NUM);
|
|
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 if (strcmp(argv[i], "--help") == 0) {
|
|
62 printf("%s\n", help_str);
|
|
63 return -1;
|
|
64 }
|
|
65 }
|
|
66
|
|
67 return 0;
|
|
68 }
|
|
69
|
|
70 //---------main関数-----------
|
|
71 int
|
|
72 cerium_main(int argc, char *argv[])
|
|
73 {
|
|
74
|
|
75 if (init(argc, argv) < 0) {
|
|
76 return -1;
|
|
77 }
|
|
78
|
|
79 task_init();
|
|
80
|
|
81 run_start();
|
|
82
|
|
83 return 0;
|
|
84 }
|