Mercurial > hg > Game > Cerium
changeset 1986:c05e575da760 draft
blocked read flag change enum tyoe in word_count
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Apr 2014 02:11:16 +0900 |
parents | d703157bb280 |
children | 1420e4521b4a |
files | example/word_count/Func.h example/word_count/main.cc |
diffstat | 2 files changed, 48 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/example/word_count/Func.h Fri Apr 18 00:24:16 2014 +0900 +++ b/example/word_count/Func.h Fri Apr 18 02:11:16 2014 +0900 @@ -8,6 +8,13 @@ TASK_PRINT, }; +// Read Type +enum { + MY_MMAP, + MY_READ, + BLOCKED_READ, +}; + #define DATA_NUM 16 #define ADD_NUM 26
--- a/example/word_count/main.cc Fri Apr 18 00:24:16 2014 +0900 +++ b/example/word_count/main.cc Fri Apr 18 02:11:16 2014 +0900 @@ -28,7 +28,7 @@ int use_iterate_all = 0; int array_task_num = 11; int spe_num = 1; -int block_read_flag = 0; +int read_type = MY_MMAP; CPU_TYPE spe_cpu = SPE_ANY; CPU_TYPE read_spe_cpu = SPE_ANY; @@ -48,6 +48,35 @@ } st_mmap_t; static void +my_read(char *filename, WordCount *w) +{ + /*マッピングだよ!*/ + int map = MAP_PRIVATE; + st_mmap_t st_mmap; + struct stat sb; + long fd = w->fd; + + if ((fd=open(filename,O_RDONLY,0666))==0) { + fprintf(stderr,"can't open %s\n",filename); + } + + if (fstat(fd,&sb)) { + fprintf(stderr,"can't fstat %s\n",filename); + } + + //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); + + if (st_mmap.file_mmap == (caddr_t)-1) { + fprintf(stderr,"Can't mmap file\n"); + perror(NULL); + exit(0); + } + + return ; +} + +static void my_mmap(char *filename, WordCount *w) { /*マッピングだよ!*/ @@ -289,10 +318,13 @@ w->read_filesize = sb->st_size; - if (block_read_flag == 1) { + if (read_type == BLOCKED_READ) { printf("[block read mode]\n"); w->file_mmap = (char*)manager->allocate(w->read_filesize); - }else { + }else if (read_type == MY_READ) { + printf("[single read mode]\n"); + my_read(filename, w); + }else if(read_type == MY_MMAP) { printf("[mmap mode]\n"); my_mmap(filename, w); } @@ -349,7 +381,7 @@ for(int i=0;i<4;i++) { /* Task を task_blocks ずつ起動する Task */ /* serialize されていると仮定する... */ - if (block_read_flag == 1) { + if (read_type == BLOCKED_READ) { t_exec = manager->create_task(BREAD_RUN_TASK_BLOCKS, (memaddr)&w->self,sizeof(memaddr),0,0); }else { @@ -407,8 +439,11 @@ 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) { + read_type = BLOCKED_READ; + } else if (strcmp(argv[i], "-r") == 0) { + read_type = MY_READ; + } + /* else if (strcmp(argv[i], "-cpu") == 0) { spe_num = atoi(argv[i+1]); i++; if (spe_num==0) spe_num = 1;