1575
|
1 #include <stdio.h>
|
|
2 #include <string.h>
|
|
3 #include "Print.h"
|
|
4 #include "Func.h"
|
|
5 #include "WordCount.h"
|
|
6
|
|
7 /* これは必須 */
|
|
8 SchedDefineTask1(Print,run_print);
|
|
9
|
|
10 static int
|
|
11 run_print(SchedTask *s, void *rbuf, void *wbuf)
|
|
12 {
|
|
13 WordCount *w = *(WordCount**)rbuf;
|
|
14 unsigned long long *idata = w->o_data;
|
|
15 // long task_num = w->task_num;
|
|
16 long status_num = w->status_num;
|
|
17 int out_task_num = w->out_task_num;
|
|
18
|
|
19 /*
|
|
20 * head_flag
|
|
21 * o_data[0]
|
|
22 * o_data[1]
|
|
23 *
|
|
24 */
|
|
25 unsigned long long word_data[2];
|
|
26
|
|
27 int flag_cal_sum = 0;
|
|
28 //printf("pad %d\n",pad);
|
|
29
|
|
30
|
|
31 /* head_tail_flag : task = 2 : 1
|
|
32 *
|
|
33 * head_tail_flag[2]
|
|
34 * ___________ __________
|
|
35 * | | |
|
|
36 * | head_flag | tail_fag |
|
|
37 * |___________|__________|
|
|
38 * [0] [1]
|
|
39 *
|
|
40 * |----------------------|
|
|
41 * unsigned long long
|
|
42 * 16byte
|
|
43 *
|
|
44 * 配列先頭の head_flag はみない
|
|
45 * 配列末尾の tail_flag はみない
|
|
46 * 担当範囲前の末尾文字が「改行と、スペース以外」(tail_flag = 1)で、
|
|
47 * 担当範囲の先頭文字が「改行とスペース」(head_flag = 0)の場合
|
|
48 * 単語数を +1 することで、整合性がとれる。
|
|
49 *
|
|
50 * ex.
|
|
51 * task_num 4
|
|
52 * head_tail_flag[8]
|
|
53 *
|
|
54 * 0 1 2 3 4 5 6 7
|
|
55 * ___ ___ ___ ___ ___ ___ ___ ___
|
|
56 * | h | t | h | t | h | t | h | t |
|
|
57 * |___|___|___|___|___|___|___|___|
|
|
58 * |-------|-------|-------|
|
|
59 * 比較 比較 比較
|
|
60 *
|
|
61 */
|
|
62
|
|
63 s->printf("start sum\n");
|
|
64
|
|
65 for (int i = 0; i < status_num; i++) {
|
|
66 word_data[i] = 0;
|
|
67 }
|
|
68
|
|
69 for (int i = 0; i < out_task_num ; i++) {
|
|
70 word_data[0] += idata[i*w->out_size+0];
|
|
71 word_data[1] += idata[i*w->out_size+1];
|
|
72 unsigned long long *head_tail_flag =
|
|
73 &idata[i*w->out_size+2];
|
|
74 if((i!=out_task_num-1)&&
|
|
75 (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) {
|
|
76 flag_cal_sum++;
|
|
77 }
|
|
78 }
|
|
79
|
|
80 word_data[0] += flag_cal_sum;
|
|
81
|
|
82 for (int i = status_num-1; i >=0; i--) {
|
|
83 s->printf("%llu ",word_data[i]);
|
|
84 }
|
|
85
|
|
86 //printf("j = %d\n",j);
|
|
87
|
|
88
|
|
89 s->printf("\n");
|
|
90
|
|
91 return 0;
|
|
92 }
|