Mercurial > hg > Members > kono > Cerium
comparison example/Pipeline/main.cc @ 963:86e50572561c
SgChange
author | tkaito |
---|---|
date | Thu, 05 Aug 2010 22:47:38 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
962:9f9b2bbc9a10 | 963:86e50572561c |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
5 #include "Func.h" | |
6 | |
7 #define DATA_NUM 12 | |
8 | |
9 extern void task_init(); | |
10 | |
11 static int task = 1; | |
12 | |
13 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | |
14 -length Number of data (default DATA_NUM (Func.h))\n\ | |
15 -count Number of task (default 1)\n"; | |
16 | |
17 | |
18 void | |
19 print_data(int *data, int size, const char *title) | |
20 { | |
21 printf("%s ---\n", title); | |
22 for (int i = 0; i < size; i++) { | |
23 printf("%2d ", data[i]); | |
24 } | |
25 printf("\n"); | |
26 } | |
27 | |
28 /** | |
29 * タスク終了後の data1, data2 の確認 | |
30 */ | |
31 void | |
32 twice_result(SchedTask *s, void *a, void *b) | |
33 { | |
34 int* data = (int*)a; | |
35 int length = (long)b; | |
36 print_data(data, length, "after"); | |
37 free(data); | |
38 } | |
39 | |
40 int length = DATA_NUM; | |
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 } | |
51 } | |
52 | |
53 return 0; | |
54 } | |
55 int | |
56 loop(SchedTask *m, void *a, void *b) | |
57 { | |
58 buf = 1-buf; | |
59 | |
60 HTask *next = m->create_task(Dummy,0,0,0,0); | |
61 next->wait_for(allexecute); | |
62 next->wait_for(rendering); | |
63 next->set_post(loop, (void*)out, (void*)length); | |
64 | |
65 // add Active Queue | |
66 next->spawn(); | |
67 HTask *allexecute = m->create_task(Allexecute,(memaddr)data[buf],sizeof(int)*length, (memaddr)out[buf], sizeof(int)*length); | |
68 allexecute->set_param(0,(memaddr)next); | |
69 | |
70 // add Active Queue | |
71 allexecute->spawn(); | |
72 | |
73 HTask *rendering = m->create_task(Rendering,(memaddr)data[1-buf],sizeof(int)*length, (memaddr)out[1-buf], sizeof(int)*length); | |
74 | |
75 rendering->set_param(0,(memaddr)next); //renderingが生成するtaskに対してwait_for する必要がある | |
76 | |
77 // add Active Queue | |
78 rendering->spawn(); | |
79 | |
80 } | |
81 | |
82 void | |
83 twice_init(TaskManager *manager) | |
84 { | |
85 HTask *twice; | |
86 | |
87 int *data = (int*)manager->allocate(sizeof(int)*length); | |
88 int *out = (int*)manager->allocate(sizeof(int)*length); | |
89 | |
90 for (int i = 0; i < length; i++) { | |
91 data[i] = i; | |
92 } | |
93 | |
94 print_data(data, length, "before"); | |
95 | |
96 /** | |
97 * Create Task | |
98 * create_task(Task ID); | |
99 */ | |
100 twice = manager->create_task(Twice,(memaddr)data,sizeof(int)*length, (memaddr)out, sizeof(int)*length); | |
101 twice->set_cpu(SPE_ANY); | |
102 | |
103 twice->set_post(twice_result, (void*)out, (void*)length); | |
104 | |
105 // add Active Queue | |
106 twice->spawn(); | |
107 } | |
108 | |
109 int | |
110 TMmain(TaskManager *manager,int argc, char *argv[]) | |
111 { | |
112 if (init(argc, argv) < 0) { | |
113 return -1; | |
114 } | |
115 | |
116 // Task Register | |
117 // ppe/task_init.cc | |
118 task_init(); | |
119 | |
120 for (int i = 0; i < task; ++i) { | |
121 twice_init(manager); | |
122 } | |
123 | |
124 return 0; | |
125 } | |
126 | |
127 /* end */ |