Mercurial > hg > Game > Cerium
annotate example/basic/main.cc @ 1407:976f7b77f0bf draft
fix Makefile
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Feb 2012 17:42:50 +0900 |
parents | 94d82f2c842f |
children | f40558ec00a8 |
rev | line source |
---|---|
109 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
5 #include "Func.h" | |
6 | |
7 extern void task_init(void); | |
8 | |
9 static int length = DATA_NUM; | |
256 | 10 static int task = 1; |
109 | 11 |
256 | 12 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ |
13 -length Number of data (default DATA_NUM (Func.h))\n\ | |
14 -count Number of task (default 1)\n"; | |
109 | 15 |
16 | |
17 void | |
256 | 18 print_data(int *data, int size, const char *title) |
109 | 19 { |
20 printf("%s ---\n", title); | |
21 for (int i = 0; i < size; i++) { | |
22 printf("%2d ", data[i]); | |
23 } | |
24 printf("\n"); | |
25 } | |
26 | |
27 /** | |
298 | 28 * タスク終了後の data1, data2 の確認 |
109 | 29 */ |
30 void | |
619 | 31 twice_result(SchedTask *s, void *a, void *b) |
109 | 32 { |
256 | 33 int* data = (int*)a; |
109 | 34 print_data(data, length, "after"); |
35 free(data); | |
36 } | |
37 | |
38 int | |
39 init(int argc, char **argv) | |
40 { | |
41 for (int i = 1; argv[i]; ++i) { | |
42 if (strcmp(argv[i], "-length") == 0) { | |
43 length = atoi(argv[++i]); | |
256 | 44 } else if (strcmp(argv[i], "-count") == 0) { |
45 task = atoi(argv[++i]); | |
109 | 46 } |
47 } | |
48 | |
49 return 0; | |
50 } | |
51 | |
52 void | |
400 | 53 twice_init(TaskManager *manager) |
109 | 54 { |
55 HTask *twice; | |
56 | |
256 | 57 int *data = (int*)manager->allocate(sizeof(int)*length); |
109 | 58 |
59 for (int i = 0; i < length; i++) { | |
60 data[i] = i; | |
61 } | |
62 | |
63 print_data(data, length, "before"); | |
64 | |
65 /** | |
66 * Create Task | |
67 * create_task(Task ID); | |
68 */ | |
69 twice = manager->create_task(TWICE_TASK); | |
70 twice->set_cpu(SPE_ANY); | |
71 | |
72 /** | |
73 * Set of Input Data | |
74 * add_inData(address of input data, size of input data); | |
75 */ | |
76 twice->add_inData(data, sizeof(int)*length); | |
77 | |
78 /** | |
79 * Set of OutPut area | |
80 * add_outData(address of output area, size of output area); | |
81 */ | |
82 twice->add_outData(data, sizeof(int)*length); | |
83 | |
84 /** | |
85 * Set 32bits parameter | |
86 * add_param(32bit parameter); | |
87 */ | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
88 twice->add_param((memaddr)length); |
109 | 89 |
293 | 90 /* |
298 | 91 * set_post() で ppe task を渡せるようにしたい |
293 | 92 */ |
619 | 93 twice->set_post(twice_result, (void*)data, 0); |
109 | 94 |
95 // add Active Queue | |
96 twice->spawn(); | |
97 } | |
98 | |
99 int | |
400 | 100 TMmain(TaskManager *manager,int argc, char *argv[]) |
109 | 101 { |
102 if (init(argc, argv) < 0) { | |
103 return -1; | |
104 } | |
105 | |
106 // Task Register | |
107 // ppe/task_init.cc | |
108 task_init(); | |
109 | |
256 | 110 for (int i = 0; i < task; ++i) { |
400 | 111 twice_init(manager); |
256 | 112 } |
109 | 113 |
114 return 0; | |
115 } |