Mercurial > hg > Game > Cerium
annotate example/Bulk/main.cc @ 688:77c89477daa8 draft
on going...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Dec 2009 18:53:46 +0900 |
parents | 25afcd4ae380 |
children | ecf63089f5bb |
rev | line source |
---|---|
659 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
688 | 5 #include "Task.h" |
659 | 6 #include "Func.h" |
7 | |
8 extern void task_init(void); | |
9 | |
10 static int length = DATA_NUM; | |
684 | 11 static int task = 10; |
12 static int count = 10; | |
659 | 13 |
14 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | |
15 -length Number of data (default DATA_NUM (Func.h))\n\ | |
16 -count Number of task (default 1)\n"; | |
17 | |
18 | |
19 void | |
20 print_data(int *data, int size, const char *title) | |
21 { | |
22 printf("%s ---\n", title); | |
23 for (int i = 0; i < size; i++) { | |
24 printf("%2d ", data[i]); | |
25 } | |
26 printf("\n"); | |
27 } | |
28 | |
29 /** | |
30 * タスク終了後の data1, data2 の確認 | |
31 */ | |
32 void | |
33 twice_result(SchedTask *s, void *a, void *b) | |
34 { | |
35 int* data = (int*)a; | |
688 | 36 int* task_buf = (int*)b; |
659 | 37 print_data(data, length, "after"); |
38 free(data); | |
688 | 39 free(task_buf); |
659 | 40 } |
41 | |
42 int | |
43 init(int argc, char **argv) | |
44 { | |
45 for (int i = 1; argv[i]; ++i) { | |
46 if (strcmp(argv[i], "-length") == 0) { | |
47 length = atoi(argv[++i]); | |
48 } else if (strcmp(argv[i], "-count") == 0) { | |
49 task = atoi(argv[++i]); | |
50 } else if (strcmp(argv[i], "-bluk") == 0) { | |
51 count = atoi(argv[++i]); | |
52 } | |
53 } | |
54 | |
55 return 0; | |
56 } | |
57 | |
58 void | |
59 twice_init(TaskManager *manager) | |
60 { | |
61 | |
62 int *data = (int*)manager->allocate(sizeof(int)*length); | |
63 | |
64 for (int i = 0; i < length; i++) { | |
65 data[i] = i; | |
66 } | |
67 | |
68 print_data(data, length, "before"); | |
69 | |
70 /** | |
71 * Create Task | |
72 * create_task(Task ID); | |
73 */ | |
688 | 74 int size = Task::count_size(2,length,0) * count; |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
75 |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
76 memaddr task_buf = (memaddr)manager->allocate(size); |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
77 HTask *twice_main = manager->create_task(TaskArray, task_buf, size, 0, 0); |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
78 |
684 | 79 int pos = 0; |
659 | 80 for(int i = 0;i<count;i++) { |
686 | 81 Task *t = twice_main->create_task(Twice,pos); |
659 | 82 int length2 = length/2; |
684 | 83 // 以下の順序でデータを追加する必要がある。 |
84 // length を先に指定すればsetは後からでも良い。 | |
659 | 85 /** |
86 * Set 32bits parameter | |
87 * add_param(32bit parameter); | |
88 */ | |
684 | 89 t->set_param_length(2); |
659 | 90 t->set_param(0, (memaddr)length2); |
91 t->set_param(1, (memaddr)length2); | |
92 /** | |
93 * Set of Input Data | |
94 * add_inData(address of input data, size of input data); | |
95 */ | |
684 | 96 t->set_inData_length(2); |
97 t->set_inData(0,data, sizeof(int)*length2); | |
98 t->set_inData(1,data+length2, sizeof(int)*length2); | |
659 | 99 /** |
684 | 100 * Set of Output area |
659 | 101 * add_outData(address of output area, size of output area); |
102 */ | |
684 | 103 t->set_outData_length(2); |
104 t->set_outData(0,data, sizeof(int)*length2); | |
105 t->set_outData(1,data+length2, sizeof(int)*length2); | |
106 pos += t->size(); | |
107 | |
686 | 108 // delete t; // Wao! |
659 | 109 } |
110 twice_main->set_cpu(SPE_ANY); | |
111 /* | |
112 * set_post() で ppe task を渡せるようにしたい | |
113 */ | |
688 | 114 twice_main->set_post(twice_result, (void*)data, (void*)task_buf); |
659 | 115 // add Active Queue |
684 | 116 twice_main->spawn(); |
659 | 117 } |
118 | |
119 int | |
120 TMmain(TaskManager *manager,int argc, char *argv[]) | |
121 { | |
122 if (init(argc, argv) < 0) { | |
123 return -1; | |
124 } | |
125 | |
126 // Task Register | |
127 // ppe/task_init.cc | |
128 task_init(); | |
129 | |
130 for (int i = 0; i < task; ++i) { | |
131 twice_init(manager); | |
132 } | |
133 | |
134 return 0; | |
135 } |