Mercurial > hg > Game > Cerium
annotate example/word_count/ppe/Print.cc @ 2054:2e7a6f40672f draft
add param(4) in FileMapReduce.cc
author | masa |
---|---|
date | Fri, 29 Jan 2016 15:56:28 +0900 |
parents | 030b8efcf357 |
children |
rev | line source |
---|---|
393 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Print.h" | |
4 #include "Func.h" | |
2052 | 5 #include "FileMapReduce.h" |
393 | 6 |
2053 | 7 #define STATUS_NUM 2 |
393 | 8 /* これは必須 */ |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
9 SchedDefineTask1(Print,run_print); |
393 | 10 |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
11 static int |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
12 run_print(SchedTask *s, void *rbuf, void *wbuf) |
393 | 13 { |
2052 | 14 MapReduce *w = (MapReduce*)s->get_input(0); |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
15 unsigned long long *idata = w->o_data; |
2053 | 16 long status_num = STATUS_NUM; |
17 int out_task_num = w->task_num; | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
18 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
19 /* |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
20 * head_flag |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
21 * o_data[0] |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
22 * o_data[1] |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
23 * |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
24 */ |
2053 | 25 unsigned long long word_data[STATUS_NUM]; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
26 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
27 int flag_cal_sum = 0; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
28 //printf("pad %d\n",pad); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
29 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
30 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
31 /* head_tail_flag : task = 2 : 1 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
32 * |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
33 * head_tail_flag[2] |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
34 * ___________ __________ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
35 * | | | |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
36 * | head_flag | tail_fag | |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
37 * |___________|__________| |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
38 * [0] [1] |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
39 * |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
40 * |----------------------| |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
41 * unsigned long long |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
42 * 16byte |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
43 * |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
44 * 配列先頭の head_flag はみない |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
45 * 配列末尾の tail_flag はみない |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
46 * 担当範囲前の末尾文字が「改行と、スペース以外」(tail_flag = 1)で、 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
47 * 担当範囲の先頭文字が「改行とスペース」(head_flag = 0)の場合 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
48 * 単語数を +1 することで、整合性がとれる。 |
1589
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
49 * * ex. |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
50 * task_num 2 |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
51 * head_tail_flag[5] |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
52 * |
1589
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
53 * 0 1 | 2 3 4 5 |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
54 * ___ ___ ___ ___ ___ ___ ___ ___ |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
55 * | W | L | h | t | W | L | h | t | |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
56 * |___|___|___|___|___|___|___|___| |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
57 * | |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
58 * |-----------| |
06f32d2da877
change explanation Print.cc
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
59 * 比較 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
60 * |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
61 */ |
393 | 62 |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
63 s->printf("start sum\n"); |
393 | 64 |
2053 | 65 for (int i = 0; i < STATUS_NUM; i++) { |
1544
5c4e3f0d372a
many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
946
diff
changeset
|
66 word_data[i] = 0; |
393 | 67 } |
68 | |
2053 | 69 int out_size = w->division_out_size / sizeof(unsigned long long); |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
70 for (int i = 0; i < out_task_num ; i++) { |
2053 | 71 word_data[0] += idata[i*out_size+0]; |
1694
1755ae347fce
use iterate for multiply
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1688
diff
changeset
|
72 // printf("idata[%d]=%lld\n",i*w->out_size+0,idata[i*w->out_size+0]); |
2053 | 73 word_data[1] += idata[i*out_size+1]; |
1544
5c4e3f0d372a
many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
946
diff
changeset
|
74 unsigned long long *head_tail_flag = |
2053 | 75 &idata[i*out_size+2]; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
76 if((i!=out_task_num-1)&& |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
77 (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) { |
1544
5c4e3f0d372a
many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
946
diff
changeset
|
78 flag_cal_sum++; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
79 } |
393 | 80 } |
81 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
82 word_data[0] += flag_cal_sum; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
83 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
84 for (int i = status_num-1; i >=0; i--) { |
1544
5c4e3f0d372a
many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
946
diff
changeset
|
85 s->printf("%llu ",word_data[i]); |
393 | 86 } |
87 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
88 //printf("j = %d\n",j); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
89 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
786
diff
changeset
|
90 |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
91 s->printf("\n"); |
393 | 92 |
93 return 0; | |
94 } |