annotate example/Pipeline/main.cc @ 2054:2e7a6f40672f draft

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