Mercurial > hg > Members > kono > Cerium
annotate example/word_count/main.cc @ 946:a8b6ee80c108
unify word count examples....
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 01 Aug 2010 21:05:35 +0900 |
parents | 45c141669de7 |
children | 6a8941ee8294 |
rev | line source |
---|---|
393 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <sys/mman.h> | |
5 #include <sys/types.h> | |
6 #include <sys/stat.h> | |
7 #include <fcntl.h> | |
8 #include <unistd.h> | |
9 #include "TaskManager.h" | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
10 #include "SchedTask.h" |
393 | 11 #include "Func.h" |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
12 #include "WordCount.h" |
393 | 13 |
400 | 14 extern void task_init(); |
393 | 15 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
16 int all = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
17 int use_task_array = 1; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
18 int use_compat = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
19 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
20 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n"; |
393 | 21 |
22 typedef struct { | |
23 caddr_t file_mmap; | |
24 off_t size; | |
25 } st_mmap_t; | |
26 | |
27 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
28 |
393 | 29 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
30 static int |
393 | 31 fix_byte(int size,int fix_byte_size) |
32 { | |
33 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; | |
34 | |
35 return size; | |
36 } | |
37 | |
38 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
39 static st_mmap_t |
393 | 40 my_mmap(char *filename) |
41 { | |
42 | |
43 /*マッピングだよ!*/ | |
44 int fd = -1; | |
45 int map = MAP_PRIVATE; | |
46 st_mmap_t st_mmap; | |
47 struct stat sb; | |
48 | |
49 if ((fd=open(filename,O_RDONLY,0666))==0) { | |
50 fprintf(stderr,"can't open %s\n",filename); | |
51 } | |
52 | |
53 if (fstat(fd,&sb)) { | |
54 fprintf(stderr,"can't fstat %s\n",filename); | |
55 } | |
56 | |
57 printf("file size %d\n",(int)sb.st_size); | |
58 | |
59 /*sizeをページングサイズの倍数にあわせる*/ | |
60 st_mmap.size = fix_byte(sb.st_size,4096); | |
61 | |
394 | 62 printf("fix 4096byte file size %d\n",(int)st_mmap.size); |
393 | 63 |
64 st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); | |
65 if (st_mmap.file_mmap == (caddr_t)-1) { | |
66 fprintf(stderr,"Can't mmap file\n"); | |
67 perror(NULL); | |
68 exit(0); | |
69 } | |
70 | |
71 return st_mmap; | |
72 | |
73 } | |
74 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
75 static void |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
76 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
77 { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
78 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
79 int array_task_num = 8; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
80 if (task_count < array_task_num) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
81 array_task_num = task_count; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
82 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
83 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
84 for (int i = 0; i < task_count; i += array_task_num) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
85 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
86 HTask *task_array; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
87 if (use_task_array) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
88 task_array = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
89 if (!all) t_next->wait_for(task_array); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
90 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
91 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
92 Task *t_exec = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
93 HTask *h_exec; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
94 for (int j = 0; j < array_task_num; j++) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
95 int i = w->task_spwaned++; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
96 if (use_task_array) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
97 t_exec = task_array->next_task_array(TASK_EXEC,t_exec); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
98 t_exec->set_inData(0,w->file_mmap + i*w->division_size, size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
99 t_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
100 } else if (use_compat) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
101 h_exec = manager->create_task(TASK_EXEC); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
102 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
103 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
104 h_exec->set_cpu(SPE_ANY); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
105 h_exec->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
106 } else { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
107 h_exec = manager->create_task(TASK_EXEC, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
108 (memaddr)(w->file_mmap + i*w->division_size), size, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
109 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
110 h_exec->set_cpu(SPE_ANY); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
111 h_exec->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
112 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
113 w->size -= size; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
114 w->task_num--; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
115 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
116 if (!use_task_array) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
117 task_array->spawn_task_array(t_exec->next()); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
118 task_array->set_cpu(SPE_ANY); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
119 task_array->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
120 } else { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
121 if (!all) t_next->wait_for(h_exec); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
122 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
123 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
124 } |
393 | 125 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
126 /** |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
127 * このTaskは、PPE上で実行されるので、並列に実行されることはない |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
128 * 二つ実行されていて、Task が足りなくなることがないようにしている。 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
129 */ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
130 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
131 SchedDefineTask1(RUN_TASK_BLOCKS,run16); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
132 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
133 static int |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
134 run16(SchedTask *manager, void *in, void *out) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
135 { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
136 WordCount *w = *(WordCount **)in; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
137 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
138 if (w->task_num < w->task_blocks) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
139 if (w->size >= w->division_size) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
140 run_tasks(manager,w,w->task_num, w->t_print, w->division_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
141 while (w->size>0) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
142 run_tasks(manager,w,1, w->t_print, w->size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
143 // printf("run16 last %d\n",w->task_num); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
144 } else { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
145 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
146 (memaddr)&w->self,sizeof(memaddr),0,0); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
147 w->t_print->wait_for(t_next); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
148 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
149 run_tasks(manager,w, w->task_blocks, t_next, w->division_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
150 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
151 t_next->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
152 // printf("run16 next %d\n",w->task_num); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
153 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
154 return 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
155 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
156 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
157 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
158 static int blocks = 48; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
159 static int division = 16; // in Kbyte |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
160 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
161 static void |
400 | 162 run_start(TaskManager *manager, char *filename) |
393 | 163 { |
164 HTaskPtr t_print; | |
165 | |
166 st_mmap_t st_mmap; | |
167 st_mmap = my_mmap(filename); | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
168 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
169 // bzero(w,sizeof(WordCount)); |
393 | 170 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
171 w->self = w; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
172 w->task_blocks = blocks; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
173 w->task_spwaned = 0; |
393 | 174 |
175 /*sizeはdivision_sizeの倍数にしている。*/ | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
176 w->size = st_mmap.size; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
177 w->file_mmap = st_mmap.file_mmap; |
393 | 178 |
179 /* 1task分のデータサイズ(byte) */ | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
180 if (w->size >= 1024*division) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
181 w->division_size = 1024 * division;/*16kbyte*/ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
182 } else { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
183 w->division_size = w->size; |
393 | 184 } |
185 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
186 printf("dvision_size %d\n",w->division_size); |
393 | 187 |
188 /* "word num" and "line num" */ | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
189 w->status_num = 2; |
393 | 190 /* taskの数 */ |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
191 w->task_num = w->size / w->division_size; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
192 w->task_num = w->task_num + (w->division_size*w->task_num < w->size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
193 int out_task_num = w->task_num; |
394 | 194 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
195 w->out_task_num = out_task_num; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
196 printf("task_num %d\n",w->task_num); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
197 printf("out_task_num %d\n",w->out_task_num); |
394 | 198 |
393 | 199 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ |
200 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
201 w->division_out_size = sizeof(unsigned long long)*4; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
202 int out_size = w->division_out_size*out_task_num; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
203 w->o_data = (unsigned long long *)manager->allocate(out_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
204 w->out_size = 4; |
393 | 205 printf("out size %d\n",out_size); |
206 | |
207 /*各SPEの結果を合計して出力するタスク*/ | |
208 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
209 t_print = manager->create_task(TASK_PRINT, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
210 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 211 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
212 w->t_print = t_print; |
783 | 213 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
214 for(int i = 0;i<2;i++) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
215 /* Task を task_blocks ずつ起動する Task */ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
216 /* serialize されていると仮定する... */ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
217 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
218 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 219 t_print->wait_for(t_exec); |
220 t_exec->spawn(); | |
394 | 221 } |
222 | |
393 | 223 t_print->spawn(); |
224 } | |
225 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
226 static char* |
393 | 227 init(int argc, char **argv) |
228 { | |
229 | |
394 | 230 char *filename = 0; |
393 | 231 |
394 | 232 for (int i = 1; argv[i]; ++i) { |
393 | 233 if (strcmp(argv[i], "-file") == 0) { |
234 filename = argv[i+1]; | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
235 } else if (strcmp(argv[i], "-division") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
236 division = atoi(argv[i+1]); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
237 } else if (strcmp(argv[i], "-block") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
238 blocks = atoi(argv[i+1]); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
239 } else if (strcmp(argv[i], "-a") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
240 // create task all at once |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
241 all = 1; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
242 } else if (strcmp(argv[i], "-c") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
243 use_task_array = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
244 use_compat = 1; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
245 } else if (strcmp(argv[i], "-s") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
246 use_task_array = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
247 use_compat = 0; |
393 | 248 } |
249 } | |
400 | 250 if (filename==0) { |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
251 puts(usr_help_str); |
400 | 252 exit(1); |
253 } | |
393 | 254 |
255 return filename; | |
256 } | |
257 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
258 |
393 | 259 int |
400 | 260 TMmain(TaskManager *manager, int argc, char *argv[]) |
393 | 261 { |
262 | |
394 | 263 char *filename = 0; |
264 filename = init(argc, argv); | |
393 | 265 |
266 if (filename < 0) { | |
267 return -1; | |
268 } | |
269 | |
270 task_init(); | |
400 | 271 run_start(manager, filename); |
393 | 272 |
273 return 0; | |
274 } | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
275 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
276 /* end */ |