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