annotate example/basic/main.cc @ 298:768452fab95e draft

from EUC to UTF-8
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 07 Jun 2009 15:17:41 +0900
parents da8edd0735f2
children 5b995810b86a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <stdio.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <stdlib.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <string.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include "TaskManager.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "Func.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 extern void task_init(void);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 static int length = DATA_NUM;
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
10 static int task = 1;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
12 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
13 -length Number of data (default DATA_NUM (Func.h))\n\
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
14 -count Number of task (default 1)\n";
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 void
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
18 print_data(int *data, int size, const char *title)
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20 printf("%s ---\n", title);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 for (int i = 0; i < size; i++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22 printf("%2d ", data[i]);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 printf("\n");
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 /**
298
768452fab95e from EUC to UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 293
diff changeset
28 * タスク終了後の data1, data2 の確認
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29 */
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30 void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 twice_result(void *a)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 {
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
33 int* data = (int*)a;
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 print_data(data, length, "after");
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 free(data);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 init(int argc, char **argv)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 for (int i = 1; argv[i]; ++i) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 if (strcmp(argv[i], "-length") == 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 length = atoi(argv[++i]);
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
44 } else if (strcmp(argv[i], "-count") == 0) {
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
45 task = atoi(argv[++i]);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53 twice_init(void)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 HTask *twice;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
57 int *data = (int*)manager->allocate(sizeof(int)*length);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 for (int i = 0; i < length; i++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 data[i] = i;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 print_data(data, length, "before");
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65 /**
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 * Create Task
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 * create_task(Task ID);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 */
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 twice = manager->create_task(TWICE_TASK);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 twice->set_cpu(SPE_ANY);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72 /**
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73 * Set of Input Data
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 * add_inData(address of input data, size of input data);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 */
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 twice->add_inData(data, sizeof(int)*length);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 /**
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 * Set of OutPut area
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 * add_outData(address of output area, size of output area);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 */
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82 twice->add_outData(data, sizeof(int)*length);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 /**
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 * Set 32bits parameter
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 * add_param(32bit parameter);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 */
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 twice->add_param(length);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89
293
da8edd0735f2 add wait_for document
e065746@localhost.localdomain
parents: 256
diff changeset
90 /*
298
768452fab95e from EUC to UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 293
diff changeset
91 * set_post() で ppe task を渡せるようにしたい
293
da8edd0735f2 add wait_for document
e065746@localhost.localdomain
parents: 256
diff changeset
92 */
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
93 twice->set_post(twice_result, (void*)data);
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95 // add Active Queue
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 twice->spawn();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99 int
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
100 TMmain(int argc, char *argv[])
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
102 if (init(argc, argv) < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
103 return -1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
104 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
105
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
106 // Task Register
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
107 // ppe/task_init.cc
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108 task_init();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109
256
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
110 for (int i = 0; i < task; ++i) {
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
111 twice_init();
2c775d229cc6 fix examples
tkaito@localhost.localdomain
parents: 109
diff changeset
112 }
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
113
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
114 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
115 }