annotate example/word_count_test/main.cc @ 839:1001c4bea1a0 draft

if unnecessary
author Yutaka_Kinjyo
date Fri, 28 May 2010 03:24:52 +0900
parents 4cdf9df6a92f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #include <stdio.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
2 #include <stdlib.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 #include <string.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 #include <sys/mman.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
5 #include <sys/types.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6 #include <sys/stat.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 #include <fcntl.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8 #include <unistd.h>
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 #include "TaskManager.h"
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
10 #include "SchedTask.h"
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 #include "Func.h"
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
12 #include "WordCount.h"
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
14 #define TASKARRAY
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
15
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 extern void task_init();
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
17
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 const char *usr_help_str = "Usage: ./word_count [-cpu spe_num] [-file filename]\n";
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
19
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
20 typedef struct {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 caddr_t file_mmap;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
22 off_t size;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
23 } st_mmap_t;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
24
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
25
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
26
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
27 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
28 static int
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
29 fix_byte(int size,int fix_byte_size)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
30 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
31 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
32
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
33 return size;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
37 static st_mmap_t
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38 my_mmap(char *filename)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41 /*マッピングだよ!*/
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
42 int fd = -1;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
43 int map = MAP_PRIVATE;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44 st_mmap_t st_mmap;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 struct stat sb;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 if ((fd=open(filename,O_RDONLY,0666))==0) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48 fprintf(stderr,"can't open %s\n",filename);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 if (fstat(fd,&sb)) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 fprintf(stderr,"can't fstat %s\n",filename);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 printf("file size %d\n",(int)sb.st_size);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 /*sizeをページングサイズの倍数にあわせる*/
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 st_mmap.size = fix_byte(sb.st_size,4096);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 printf("fix 4096byte file size %d\n",(int)st_mmap.size);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 if (st_mmap.file_mmap == (caddr_t)-1) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 fprintf(stderr,"Can't mmap file\n");
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 perror(NULL);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
66 exit(0);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
68
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
69 return st_mmap;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
70
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
72
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
73 #ifdef TASKARRAY
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
74 static HTask *
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
75 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size)
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
76 {
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
77 HTask *t_exec = manager->create_task_array(TASK_EXEC,task_count,0,1,1);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
78 Task *t = 0;
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
79 for (int j = 0; j < task_count && w->size>0; j++) {
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
80 int i = w->task_spwaned++;
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
81 // printf("div %0x\n", (w->file_mmap + i*w->division_size));
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
82 t = t_exec->next_task_array(TASK_EXEC, t);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
83 t->set_inData(0, (memaddr)(w->file_mmap + i*w->division_size), size);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
84 t->set_outData(0, (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
85 w->size -= size;
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
86 w->task_num--;
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
87 }
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
88 if (w->size!=0) {
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
89 printf("bad align %d\n",w->size);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
90 }
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
91 t_exec->spawn_task_array(t->next());
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
92 t_exec->set_cpu(SPE_ANY);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
93 t_next->wait_for(t_exec);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
94 t_exec->spawn();
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
95 return t_exec;
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
96 }
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
97 #else
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
98 static void
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
99 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size)
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
100 {
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
101 HTaskPtr t_exec = 0;
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
102 for (int j = 0; j < task_count && w->size>0; j++) {
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
103 int i = w->task_spwaned++;
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
104 // printf("div %0x\n", (w->file_mmap + i*w->division_size));
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
105 t_exec = manager->create_task(TASK_EXEC,
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
106 (memaddr)(w->file_mmap + i*w->division_size), size,
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
107 (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
108 t_exec->set_cpu(SPE_ANY);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
109 t_next->wait_for(t_exec);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
110 t_exec->spawn();
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
111 w->size -= size;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
112 w->task_num--;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
113 }
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
114 return t_exec;
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
115 }
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
116 #endif
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
117
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
118 SchedDefineTask1(RUN_TASK_BLOCKS,run16);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
119
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
120 static int
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
121 run16(SchedTask *manager, void *in, void *out)
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
122 {
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
123 WordCount *w = *(WordCount **)in;
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
124
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
125 if (w->task_num < w->task_blocks) {
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
126 if (w->size >= w->division_size)
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
127 run_tasks(manager,w,w->task_blocks, w->t_print, w->division_size);
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
128 while (w->size>0)
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
129 run_tasks(manager,w,1, w->t_print, w->size);
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
130 // printf("run16 last %d\n",w->task_num);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
131 } else {
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
132 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS,
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
133 (memaddr)&w->self,sizeof(memaddr),0,0);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
134 w->t_print->wait_for(t_next);
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
135 HTask *wait = next_wait_task(w, t_next);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
136 HTask *exec = run_tasks(manager,w, w->task_blocks, w->t_print, w->division_size);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
137 if (wait) {
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
138 wait->wait_for(t_next);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
139 wait->wait_for(exec);
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
140 }
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
141 t_next->spawn();
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
142 // printf("run16 next %d\n",w->task_num);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
143 }
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
144 return 0;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
145 }
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
146
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
147 static int blocks = 48;
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
148 static int division = 16; // in Kbyte
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
149 static int pipeline = 16; // Pipelined Tasks Blocks
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
150 static int profile = 0;
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
151
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
152 static void
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
153 run_start(TaskManager *manager, char *filename)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
154 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
155 HTaskPtr t_print;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
156
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
157 st_mmap_t st_mmap;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
158 st_mmap = my_mmap(filename);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
159 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
160 // bzero(w,sizeof(WordCount));
800
54f0180cea0f run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 713
diff changeset
161 set_pipeline_count(w,manager,pipeline);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
162
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
163 w->self = w;
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
164 w->task_blocks = blocks;
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
165 w->task_spwaned = 0;
810
4cdf9df6a92f add KeyID.h
yutaka@localhost.localdomain
parents: 800
diff changeset
166 //w->waiting = 0;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
167
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
168 /*sizeはdivision_sizeの倍数にしている。*/
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
169 w->size = st_mmap.size;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
170 w->file_mmap = st_mmap.file_mmap;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
171
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
172 /* 1task分のデータサイズ(byte) */
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
173 if (w->size >= 1024*division) {
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
174 w->division_size = 1024 * division;/*16kbyte*/
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
175 } else {
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
176 w->division_size = w->size;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
177 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
178
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
179 printf("dvision_size %d\n",w->division_size);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
180
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
181 /* "word num" and "line num" */
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
182 w-> status_num = 2;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
183 /* taskの数 */
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
184 w-> task_num = w->size / w->division_size;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
185 int out_task_num = w->task_num + (w->division_size*w->task_num < w->size);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
186
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
187 w->out_task_num = out_task_num;
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
188 printf("task_num %d\n",w->task_num);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
189
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
190 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
191
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
192 w-> division_out_size = sizeof(unsigned long long)*4;
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
193 int out_size = w->division_out_size*out_task_num;
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
194 w->o_data = (unsigned long long *)manager->allocate(out_size);
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
195 w-> out_size = 4;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
196 printf("out size %d\n",out_size);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
197
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
198 /*各SPEの結果を合計して出力するタスク*/
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
199
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
200 t_print = manager->create_task(TASK_PRINT,
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
201 (memaddr)&w->self,sizeof(memaddr),0,0);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
202
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
203 w->t_print = t_print;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
204
670
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
205 for(int i = 0;i<1;i++) {
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
206 /* Task を task_blocks ずつ起動する Task */
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
207 /* serialize されていると仮定する... */
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
208 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
209 (memaddr)&w->self,sizeof(memaddr),0,0);
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
210 t_exec->spawn();
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
211 t_print->wait_for(t_exec);
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
212 }
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
213
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
214 t_print->spawn();
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
215 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
216
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
217 static char*
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
218 init(int argc, char **argv)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
219 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
220
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
221 char *filename = 0;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
222
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
223 for (int i = 1; argv[i]; ++i) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
224 if (strcmp(argv[i], "-file") == 0) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
225 filename = argv[i+1];
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
226 } else if (strcmp(argv[i], "-division") == 0) {
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
227 division = atoi(argv[i+1]);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
228 } else if (strcmp(argv[i], "-block") == 0) {
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
229 blocks = atoi(argv[i+1]);
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
230 } else if (strcmp(argv[i], "-p") == 0) {
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
231 profile = 1;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
232 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
233 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
234 if (filename==0) {
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
235 printf("usage: %s [-block 10] -file filename\n",argv[0]);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
236 exit(1);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
237 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
238
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
239 return filename;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
240 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
241
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
242
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
243 int
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
244 TMmain(TaskManager *manager, int argc, char *argv[])
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
245 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
246
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
247 char *filename = 0;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
248 filename = init(argc, argv);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
249
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
250 if (filename < 0) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
251 return -1;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
252 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
253
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
254 task_init();
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
255 run_start(manager, filename);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
256
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
257 return 0;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
258 }
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
259
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
260 /* end */