annotate example/Pipeline/main.cc @ 963:86e50572561c

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