annotate example/regex_masa/ppe/Print.cc @ 1582:046695c73cb0 draft

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