# HG changeset patch # User e065725@localhost.localdomain # Date 1253108020 -32400 # Node ID e08d0aa9436780f24f97eb0d73bb9e6d2fbf1697 # Parent 72b73beb33256bb916dbd0a7127eb697e0153274 debug word_count diff -r 72b73beb3325 -r e08d0aa94367 example/word_count/main.cc --- a/example/word_count/main.cc Tue Sep 15 16:30:46 2009 +0900 +++ b/example/word_count/main.cc Wed Sep 16 22:33:40 2009 +0900 @@ -11,8 +11,7 @@ extern void task_init(void); -const char *usr_help_str = "Usage: ./dependency [-cpu spe_num] [-nodepend]\n\ - -nodepend No Depenendcy"; +const char *usr_help_str = "Usage: ./word_count [-cpu spe_num] [-file filename]\n"; typedef struct { caddr_t file_mmap; @@ -53,7 +52,7 @@ /*sizeをページングサイズの倍数にあわせる*/ st_mmap.size = fix_byte(sb.st_size,4096); - printf("fix 4096byte file size %d\n",st_mmap.size); + printf("fix 4096byte file size %d\n",(int)st_mmap.size); st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); if (st_mmap.file_mmap == (caddr_t)-1) { @@ -90,19 +89,20 @@ division_size = size; } - division_size = 4096; - printf("dvision_size %d\n",division_size); /* "word num" and "line num" */ int status_num = 2; /* taskの数 */ int task_num = size / division_size; + int out_task_num = task_num + (division_size*task_num < size); + printf("task_num %d\n",task_num); + /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ int division_out_size = 16; /* out用のデータのサイズ。*/ - int out_size = division_out_size*task_num; + int out_size = division_out_size*out_task_num; unsigned long long *o_data = (unsigned long long*)manager->allocate(out_size); @@ -112,13 +112,9 @@ t_print = manager->create_task(TASK_PRINT); t_print->add_inData(o_data, out_size); - t_print->add_param(task_num); + t_print->add_param(out_task_num); t_print->add_param(status_num); - int length = division_size; - - printf("length %d\n",length); - /*各SPEに処理するデータを割り振る。*/ /*渡すデータの最後が文字かどうか。(スペース、改行以外)*/ @@ -129,7 +125,7 @@ t_exec = manager->create_task(TASK_EXEC); t_exec->add_inData(file_mmap + i*division_size, division_size); t_exec->add_outData(o_data + i*status_num, division_out_size); - t_exec->add_param(length); + t_exec->add_param(division_size); t_exec->add_param(word_flag); t_exec->set_cpu(SPE_ANY); t_print->wait_for(t_exec); @@ -137,8 +133,23 @@ word_flag = ((file_mmap[(i+1)*division_size-1] != 0x20) && (file_mmap[(i+1)*division_size-1] != 0x0A)); + size -= division_size; + } + if (size) { + + t_exec = manager->create_task(TASK_EXEC); + t_exec->add_inData(file_mmap + i*division_size, size); + t_exec->add_outData(o_data + i*status_num, division_out_size); + t_exec->add_param(size); + t_exec->add_param(word_flag); + t_exec->set_cpu(SPE_ANY); + t_print->wait_for(t_exec); + t_exec->spawn(); + } + + t_print->spawn(); } @@ -146,14 +157,12 @@ init(int argc, char **argv) { - char *filename; + char *filename = 0; - for (int i = 1; argv[i]; ++i) { - + for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-file") == 0) { filename = argv[i+1]; } - } return filename; @@ -163,8 +172,8 @@ TMmain(int argc, char *argv[]) { - char *filename = init(argc, argv); - + char *filename = 0; + filename = init(argc, argv); if (filename < 0) { return -1; diff -r 72b73beb3325 -r e08d0aa94367 example/word_count/spe/Exec.cc --- a/example/word_count/spe/Exec.cc Tue Sep 15 16:30:46 2009 +0900 +++ b/example/word_count/spe/Exec.cc Wed Sep 16 22:33:40 2009 +0900 @@ -47,12 +47,6 @@ word_flag = 1; } - /*else ((i_data[i] != 0x20) && (i_data[i] != 0x0A)) { - //printf("文字 数 = %d\n", word_num + word_flag); - word_num += word_flag; - word_flag = 0; - }*/ - else { word_num += word_flag; word_flag = 0;