annotate example/word_count_test/main.cc @ 672:27fec8c70c9c draft

add profiling code
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 05 Dec 2009 20:20:08 +0900
parents 87040ec6b5f6
children 5e5e8eb8da5a
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
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
14 extern void task_init();
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
15
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 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
17
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 typedef struct {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
19 caddr_t file_mmap;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
20 off_t size;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 } st_mmap_t;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
22
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
23
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
24
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
25 /*与えられた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
26 static int
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
27 fix_byte(int size,int fix_byte_size)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
28 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
29 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
30
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
31 return 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
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
35 static st_mmap_t
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 my_mmap(char *filename)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38
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 int fd = -1;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41 int map = MAP_PRIVATE;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
42 st_mmap_t st_mmap;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
43 struct stat sb;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 if ((fd=open(filename,O_RDONLY,0666))==0) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 fprintf(stderr,"can't open %s\n",filename);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 if (fstat(fd,&sb)) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 fprintf(stderr,"can't fstat %s\n",filename);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 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
54
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 /*sizeをページングサイズの倍数にあわせる*/
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56 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
57
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 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
59
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 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
61 if (st_mmap.file_mmap == (caddr_t)-1) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 fprintf(stderr,"Can't mmap file\n");
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 perror(NULL);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 exit(0);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
66
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 return st_mmap;
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 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
70
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
71 static void
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
72 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
73 {
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
74 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
75 int i = w->task_spwaned++;
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
76 #ifdef SIMPLE_TASK
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
77 // printf("div %0x\n", (w->file_mmap + i*w->division_size));
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
78 HTaskPtr t_exec = manager->create_task(TASK_EXEC,
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
79 (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
80 (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
81 #else
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
82 HTaskPtr t_exec = manager->create_task(TASK_EXEC);
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
83 if (size>w->size) size = w->size;
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
84 t_exec->add_inData(w->file_mmap + i*w->division_size, size);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
85 t_exec->add_outData(w->o_data + i*w->status_num, w->division_out_size);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
86 t_exec->add_outData(w->head_tail_flag + i*w->pad, w->division_out_size);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
87 t_exec->add_param(size);
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
88 #endif
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
89 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
90 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
91 t_exec->spawn();
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
92 w->size -= size;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
93 w->task_num--;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
94 }
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
95 }
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
96
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
97 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
98
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
99 static int
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
100 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
101 {
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
102 #ifdef SIMPLE_TASK
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
103 WordCount *w = *(WordCount **)in;
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
104 #else
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
105 WordCount *w = (WordCount *)manager->get_param(0);
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
106 #endif
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
107
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
108 if (w->task_num < w->task_blocks) {
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
109 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
110 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
111 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
112 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
113 // 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
114 } else {
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
115 #ifdef SIMPLE_TASK
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
116 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
117 (memaddr)&w->self,sizeof(memaddr),0,0);
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
118 #else
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
119 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
120 t_next->set_param(0,(void*)w);
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
121 #endif
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
122 w->t_print->wait_for(t_next);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
123
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
124 run_tasks(manager,w, w->task_blocks, t_next, w->division_size);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
125
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
126 t_next->spawn();
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
127 // 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
128 }
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
129 return 0;
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
130 }
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
131
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
132
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
133 static int blocks = 48;
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
134 static int division = 16; // in Kbyte
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
135 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
136
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
137 static void
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
138 run_start(TaskManager *manager, char *filename)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
139 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
140 HTaskPtr t_print;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
141
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
142 st_mmap_t st_mmap;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
143 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
144 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
145 // bzero(w,sizeof(WordCount));
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
146
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
147 w->self = w;
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
148 w->task_blocks = blocks;
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
149 w->task_spwaned = 0;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
150
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
151 /*sizeはdivision_sizeの倍数にしている。*/
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
152 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
153 w->file_mmap = st_mmap.file_mmap;
658
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 /* 1task分のデータサイズ(byte) */
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
156 if (w->size >= 1024*division) {
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
157 w->division_size = 1024 * division;/*16kbyte*/
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
158 } else {
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
159 w->division_size = w->size;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
160 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
161
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
162 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
163
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
164 /* "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
165 w-> status_num = 2;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
166 /* taskの数 */
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
167 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
168 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
169
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
170 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
171 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
172
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
173 /* 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
174
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
175 #ifdef SIMPLE_TASK
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
176 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
177 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
178 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
179 w-> out_size = 4;
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
180 #else
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
181 w-> division_out_size = 16;
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
182 int out_size = w->division_out_size*out_task_num;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
183 /* out用のデータのサイズ。*/
669
1d9608e6965f fix non SIMPLE_TASK code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 667
diff changeset
184 caddr_t p = (caddr_t) manager->allocate(out_size*2);
1d9608e6965f fix non SIMPLE_TASK code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 667
diff changeset
185 w->o_data = (unsigned long long*)p;
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
186 //bzero(w->o_data,out_size);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
187
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
188 w-> pad = 2;
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
189 w->head_tail_flag = (unsigned long long*)(p+out_size);
664
beb0f17c19f9 word count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 663
diff changeset
190 // bzero(w->head_tail_flag,out_size);
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
191 #endif
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
192 printf("out size %d\n",out_size);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
193
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
194 /*各SPEの結果を合計して出力するタスク*/
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
195
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
196 if (profile) {
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
197 manager->start_profile();
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
198 }
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
199
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
200 #ifdef SIMPLE_TASK
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
201 t_print = manager->create_task(TASK_PRINT,
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
202 (memaddr)&w->self,sizeof(memaddr),0,0);
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
203 #else
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
204 t_print = manager->create_task(TASK_PRINT);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
205 t_print->add_inData(w->o_data, out_size);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
206 t_print->add_inData(w->head_tail_flag, out_size);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
207 t_print->add_param(out_task_num);
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
208 t_print->add_param(w->status_num);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
209 t_print->add_param(out_task_num);
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
210 t_print->add_param(w->pad);
667
ae1d1eebf9ff SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 666
diff changeset
211 #endif
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
212
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
213 w->t_print = t_print;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
214
670
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
215 for(int i = 0;i<1;i++) {
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
216 /* Task を task_blocks ずつ起動する Task */
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
217 /* serialize されていると仮定する... */
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
218 #ifdef SIMPLE_TASK
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
219 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
220 (memaddr)&w->self,sizeof(memaddr),0,0);
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
221 #else
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
222 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS);
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
223 t_exec->set_param(0,(void*)w);
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
224 #endif
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
225 t_exec->spawn();
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
226 t_print->wait_for(t_exec);
87040ec6b5f6 add header.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 669
diff changeset
227 }
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
228
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
229 t_print->spawn();
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
230 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
231
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
232 static char*
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
233 init(int argc, char **argv)
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
234 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
235
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
236 char *filename = 0;
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 for (int i = 1; argv[i]; ++i) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
239 if (strcmp(argv[i], "-file") == 0) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
240 filename = argv[i+1];
666
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
241 } else if (strcmp(argv[i], "-division") == 0) {
f02b3338b91b simplify word_count
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 665
diff changeset
242 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
243 } 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
244 blocks = atoi(argv[i+1]);
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
245 } else if (strcmp(argv[i], "-p") == 0) {
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
246 profile = 1;
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
247 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
248 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
249 if (filename==0) {
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
250 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
251 exit(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 return filename;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
255 }
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
256
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
257 static void
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
258 myTMend(TaskManager *manager)
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
259 {
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
260 manager->show_profile();
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
261 }
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
262
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
263 int
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
264 TMmain(TaskManager *manager, int argc, char *argv[])
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
265 {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
266
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
267 char *filename = 0;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
268 filename = init(argc, argv);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
269
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
270 if (filename < 0) {
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
271 return -1;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
272 }
672
27fec8c70c9c add profiling code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 670
diff changeset
273 manager->set_TMend(myTMend);
658
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
274
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
275 task_init();
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
276 run_start(manager, filename);
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
277
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
278 return 0;
c253468da197 add word_count_test
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
279 }
663
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
280
ad4b6b556483 incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
281 /* end */