Mercurial > hg > Game > Cerium
changeset 1980:aa5fabf2d4b2 draft
remove error and warning (not perform check)
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 13 Mar 2014 03:01:33 +0900 |
parents | 889472b0e6d5 |
children | 8403130d65ad |
files | example/word_count/main.cc |
diffstat | 1 files changed, 26 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/example/word_count/main.cc Thu Mar 13 02:43:35 2014 +0900 +++ b/example/word_count/main.cc Thu Mar 13 03:01:33 2014 +0900 @@ -28,9 +28,12 @@ int use_iterate_all = 0; int array_task_num = 11; int spe_num = 1; +int block_read_flag = 0; + CPU_TYPE spe_cpu = SPE_ANY; CPU_TYPE read_spe_cpu = SPE_ANY; -const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-g] [-file filename]\n"; + +const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-g] [-file filename] [-br]\n"; static double getTime() { @@ -53,18 +56,16 @@ return size; } - -static st_mmap_t -my_mmap(char *filename) +static void +my_mmap(char *filename, WordCount *w) { - /*マッピングだよ!*/ - int fd = -1; int map = MAP_PRIVATE; st_mmap_t st_mmap; struct stat sb; + long fd = w->fd; - if ((fd=open(filename,O_RDWR,0666))==0) { + if ((fd=open(filename,O_RDONLY,0666))==0) { fprintf(stderr,"can't open %s\n",filename); } @@ -72,46 +73,40 @@ fprintf(stderr,"can't fstat %s\n",filename); } - printf("file size %d\n",(int)sb.st_size); + //madvise(w->file_mmap, w->read_filesize, POSIX_MADV_NORMAL); + w->file_mmap = (char*)mmap(NULL,w->read_filesize,PROT_READ,map,fd,(off_t)0); - /*sizeをページングサイズの倍数にあわせる*/ - st_mmap.size = fix_byte(sb.st_size,4096); - - printf("fix 4096byte file size %d\n",(int)st_mmap.size); - - st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ|PROT_WRITE,map,fd,(off_t)0); if (st_mmap.file_mmap == (caddr_t)-1) { fprintf(stderr,"Can't mmap file\n"); perror(NULL); exit(0); } - return st_mmap; - + return ; } static void -run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) +run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_read, HTaskPtr t_next, int size) { - + if (task_count < array_task_num) { array_task_num = task_count; if (task_count<=0) return; } - for (int i = 0; i < task_count; i += array_task_num) { HTask *task_array; if (use_task_array) { int task_num = (w->size+size-1)/size; if (task_num>array_task_num) task_num = array_task_num; task_array = manager->create_task_array(TASK_EXEC,task_num,1,1,1); + if (t_read != 0) task_array->wait_for(t_read); if (!all) { t_next->wait_for(task_array); } else { w->t_print->wait_for(task_array); } } - + Task *t_exec = 0; HTask *h_exec = 0; for (int j = 0; j < array_task_num; j++) { @@ -235,9 +230,9 @@ t_read->set_param(1,w->task_spawned*w->division_size); t_read->set_outData(0, w->file_mmap + w->task_spawned * w->division_size, w->task_blocks * w->division_size); - run_tasks(manager,w, w->task_blocks, t_read, t_next, w->division_size + w->extra_len); + run_tasks(manager,w, w->task_blocks, t_read, t_next, w->division_size); - t_read->set_param(2,w->task_spawned*w->division_size + w->extra_len); + t_read->set_param(2,w->task_spawned*w->division_size); t_read->spawn(); t_next->spawn(); @@ -253,21 +248,21 @@ WordCount *w = *(WordCount **)in; if(use_iterate_all) { - run_tasks(manager, w, w->task_num, w->t_print, w->division_size); + run_tasks(manager, w, w->task_num, 0, w->t_print, w->division_size); } else if (w->task_num < w->task_blocks) { // last case while (w->size >= w->division_size) - run_tasks(manager,w,w->task_num, w->t_print, w->division_size); + run_tasks(manager,w,w->task_num,0,w->t_print, w->division_size); // remaining data while (w->size>0) - run_tasks(manager,w,1, w->t_print, w->size); + run_tasks(manager,w,1,0, w->t_print, w->size); // printf("run16 last %d\n",w->task_num); } else { HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, (memaddr)&w->self,sizeof(memaddr),0,0); w->t_print->wait_for(t_next); - - run_tasks(manager,w, w->task_blocks, t_next, w->division_size); + + run_tasks(manager,w, w->task_blocks,0, t_next, w->division_size); t_next->spawn(); // printf("run16 next %d\n",w->task_num); @@ -317,9 +312,7 @@ w->self = w; w->task_spawned = 0; - /*sizeはdivision_sizeの倍数にしている。*/ - w->size = w->file_size = st_mmap.size; - w->file_mmap = st_mmap.file_mmap; + w->size = w->file_size; printf("w %lx\n",(long)w); /* 1task分のデータサイズ(byte) */ @@ -329,7 +322,7 @@ w->division_size = w->size; } - printf("dvision_size %ld\n",w->division_size); + printf("division_size %ld\n",w->division_size); /* "word num" and "line num" */ w->status_num = 2; @@ -422,6 +415,8 @@ use_iterate_all = 1; use_iterate = 1; use_task_array = 0; + } else if (strcmp(argv[i], "-br") == 0) { + block_read_flag = 1; } /* else if (strcmp(argv[i], "-cpu") == 0) { spe_num = atoi(argv[i+1]); i++;