Mercurial > hg > Game > Cerium
annotate example/word_count_test/spe/Exec.cc @ 667:ae1d1eebf9ff draft
SimpeTask WordCount Worked.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 04:23:36 +0900 |
parents | 77d9e3bc25b2 |
children | 07351a5a51c9 |
rev | line source |
---|---|
658 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
5 | |
6 /* これは必須 */ | |
7 SchedDefineTask(Exec); | |
8 | |
9 static int | |
10 run(SchedTask *s, void *rbuf, void *wbuf) | |
11 { | |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
12 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
13 char *i_data = (char *)rbuf; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
14 unsigned long long *o_data = (unsigned long long*)wbuf; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
15 unsigned long long *head_tail_flag = o_data +2; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
16 int length = s->read_size(); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
17 #else |
665 | 18 char *i_data = (char*)s->get_input(rbuf, 0); |
658 | 19 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); |
20 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ | |
21 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); | |
22 int length = (long)s->get_param(0); | |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
23 #endif |
658 | 24 int word_flag = 0; |
25 int word_num = 0; | |
26 int line_num = 0; | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
27 int i = 0; |
658 | 28 |
29 /*文字なら1,スペースか改行なら0*/ | |
665 | 30 head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A); |
31 word_num -= 1-head_tail_flag[0]; | |
658 | 32 |
33 for (; i < length; i++) { | |
34 | |
35 //s->printf("[SPE%d]%c",id,i_data[i]); | |
36 | |
37 | |
665 | 38 if (i_data[i] == 0x20) { |
658 | 39 //s->printf("スペース\n"); |
40 word_flag = 1; | |
41 } | |
42 | |
665 | 43 else if (i_data[i] == 0x0A) { |
658 | 44 //s->printf("改行\n"); |
45 line_num += 1; | |
46 word_flag = 1; | |
47 } | |
48 | |
49 else { | |
50 word_num += word_flag; | |
51 word_flag = 0; | |
52 } | |
53 | |
54 } | |
55 | |
56 word_num += word_flag; | |
57 /*文字なら1,スペースか改行なら0*/ | |
58 //printf("last word %c",i_data[i-1]); | |
665 | 59 head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A); |
658 | 60 |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
665
diff
changeset
|
61 // s->printf("SPE word %d line %d\n",word_num,line_num); |
658 | 62 |
63 o_data[0] = (unsigned long long)word_num; | |
64 o_data[1] = (unsigned long long)line_num; | |
65 | |
66 return 0; | |
67 } |