Mercurial > hg > Members > kono > Cerium
annotate example/word_count_test/ppe/Print.cc @ 667:d753b4f6b129
SimpeTask WordCount Worked.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 04:23:36 +0900 |
parents | 4615489c5faa |
children | 4af9d20cf3af |
rev | line source |
---|---|
661 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Print.h" | |
4 #include "Func.h" | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
5 #include "WordCount.h" |
661 | 6 |
7 /* これは必須 */ | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
8 SchedDefineTask1(Print,run_print); |
661 | 9 |
10 static int | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
11 run_print(SchedTask *s, void *rbuf, void *wbuf) |
661 | 12 { |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
13 #ifdef SIMPLE_TASK |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
14 WordCount *w = *(WordCount**)rbuf; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
15 unsigned long long *idata = w->o_data; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
16 // long task_num = w->task_num; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
17 long status_num = w->status_num; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
18 int out_task_num = w->out_task_num; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
19 |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
20 /* |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
21 * head_flag |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
22 * o_data[0] |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
23 * o_data[1] |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
24 * |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
25 */ |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
26 #else |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
27 int pad = w->pad; |
661 | 28 unsigned long long *idata = (unsigned long long*)s->get_input(rbuf, 0); |
29 long task_num = (long)s->get_param(0); | |
30 long status_num = (long)s->get_param(1); | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
31 // int out_task_num = (int)s->get_param(2); |
661 | 32 int pad = (int)s->get_param(3); |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
33 #endif |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
34 unsigned long long word_data[2]; |
661 | 35 |
36 int flag_cal_sum = 0; | |
37 //printf("pad %d\n",pad); | |
38 | |
39 | |
40 /* head_tail_flag : task = 2 : 1 | |
41 * | |
42 * head_tail_flag[2] | |
43 * ___________ __________ | |
44 * | | | | |
45 * | head_flag | tail_fag | | |
46 * |___________|__________| | |
47 * [0] [1] | |
48 * | |
49 * |----------------------| | |
50 * unsigned long long | |
51 * 16byte | |
52 * | |
53 * 配列先頭の head_flag はみない | |
54 * 配列末尾の tail_flag はみない | |
55 * 担当範囲前の末尾文字が「改行と、スペース以外」(tail_flag = 1)で、 | |
56 * 担当範囲の先頭文字が「改行とスペース」(head_flag = 0)の場合 | |
57 * 単語数を +1 することで、整合性がとれる。 | |
58 * | |
59 * ex. | |
60 * task_num 4 | |
61 * head_tail_flag[8] | |
62 * | |
63 * 0 1 2 3 4 5 6 7 | |
64 * ___ ___ ___ ___ ___ ___ ___ ___ | |
65 * | h | t | h | t | h | t | h | t | | |
66 * |___|___|___|___|___|___|___|___| | |
67 * |-------|-------|-------| | |
68 * 比較 比較 比較 | |
69 * | |
70 */ | |
71 | |
72 s->printf("start sum\n"); | |
73 | |
74 for (int i = 0; i < status_num; i++) { | |
75 word_data[i] = 0; | |
76 } | |
77 | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
78 #ifdef SIMPLE_TASK |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
79 for (int i = 0; i < out_task_num ; i++) { |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
80 word_data[0] += idata[i*w->out_size+0]; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
81 word_data[1] += idata[i*w->out_size+1]; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
82 unsigned long long *head_tail_flag = |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
83 &idata[i*w->out_size+2]; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
84 if((i!=out_task_num-1)&& |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
85 (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) { |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
86 flag_cal_sum++; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
87 } |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
88 } |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
89 #else |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
90 for (int i = 1; i < out_task_num * pad - pad; i += pad) { |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
91 //printf("%llu ",head_tail_flag[i]); |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
92 //printf("%llu\n",head_tail_flag[i+1]); |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
93 if((head_tail_flag[i] == 1) && (head_tail_flag[i+1] == 0)) { |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
94 flag_cal_sum++; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
95 } |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
96 } |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
97 |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
98 for (int i = 0; i < out_task_num*status_num; i += status_num) { |
661 | 99 for (int j = 0; j < status_num; j++) { |
100 word_data[j] += idata[i+j]; | |
101 } | |
102 } | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
103 #endif |
661 | 104 |
105 word_data[0] += flag_cal_sum; | |
106 | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
107 for (int i = status_num-1; i >=0; i--) { |
661 | 108 s->printf("%llu ",word_data[i]); |
109 } | |
110 | |
111 //printf("j = %d\n",j); | |
112 | |
113 | |
114 s->printf("\n"); | |
115 | |
116 return 0; | |
117 } |