Mercurial > hg > Members > kono > Cerium
view 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 |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include "Print.h" #include "Func.h" #include "WordCount.h" /* これは必須 */ SchedDefineTask1(Print,run_print); static int run_print(SchedTask *s, void *rbuf, void *wbuf) { #ifdef SIMPLE_TASK WordCount *w = *(WordCount**)rbuf; unsigned long long *idata = w->o_data; // long task_num = w->task_num; long status_num = w->status_num; int out_task_num = w->out_task_num; /* * head_flag * o_data[0] * o_data[1] * */ #else int pad = w->pad; unsigned long long *idata = (unsigned long long*)s->get_input(rbuf, 0); long task_num = (long)s->get_param(0); long status_num = (long)s->get_param(1); // int out_task_num = (int)s->get_param(2); int pad = (int)s->get_param(3); #endif unsigned long long word_data[2]; int flag_cal_sum = 0; //printf("pad %d\n",pad); /* head_tail_flag : task = 2 : 1 * * head_tail_flag[2] * ___________ __________ * | | | * | head_flag | tail_fag | * |___________|__________| * [0] [1] * * |----------------------| * unsigned long long * 16byte * * 配列先頭の head_flag はみない * 配列末尾の tail_flag はみない * 担当範囲前の末尾文字が「改行と、スペース以外」(tail_flag = 1)で、 * 担当範囲の先頭文字が「改行とスペース」(head_flag = 0)の場合 * 単語数を +1 することで、整合性がとれる。 * * ex. * task_num 4 * head_tail_flag[8] * * 0 1 2 3 4 5 6 7 * ___ ___ ___ ___ ___ ___ ___ ___ * | h | t | h | t | h | t | h | t | * |___|___|___|___|___|___|___|___| * |-------|-------|-------| * 比較 比較 比較 * */ s->printf("start sum\n"); for (int i = 0; i < status_num; i++) { word_data[i] = 0; } #ifdef SIMPLE_TASK for (int i = 0; i < out_task_num ; i++) { word_data[0] += idata[i*w->out_size+0]; word_data[1] += idata[i*w->out_size+1]; unsigned long long *head_tail_flag = &idata[i*w->out_size+2]; if((i!=out_task_num-1)&& (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) { flag_cal_sum++; } } #else for (int i = 1; i < out_task_num * pad - pad; i += pad) { //printf("%llu ",head_tail_flag[i]); //printf("%llu\n",head_tail_flag[i+1]); if((head_tail_flag[i] == 1) && (head_tail_flag[i+1] == 0)) { flag_cal_sum++; } } for (int i = 0; i < out_task_num*status_num; i += status_num) { for (int j = 0; j < status_num; j++) { word_data[j] += idata[i+j]; } } #endif word_data[0] += flag_cal_sum; for (int i = status_num-1; i >=0; i--) { s->printf("%llu ",word_data[i]); } //printf("j = %d\n",j); s->printf("\n"); return 0; }