Mercurial > hg > Game > Cerium
changeset 1855:69250f6636e0 draft
insert divide fileread in regex_mas (cannot running)
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 22 Dec 2013 18:53:03 +0900 |
parents | c21bd32e20b9 |
children | 429cf7e669a1 |
files | example/regex_mas/Func.h example/regex_mas/main.cc example/regex_mas/task_init.cc |
diffstat | 3 files changed, 103 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/example/regex_mas/Func.h Sun Dec 22 11:59:03 2013 +0900 +++ b/example/regex_mas/Func.h Sun Dec 22 18:53:03 2013 +0900 @@ -1,7 +1,9 @@ enum { #include "SysTasks.h" TASK_EXEC, + TASK_READ, RUN_TASK_BLOCKS, + RUN_READ_BLOCKS, TASK_PRINT, };
--- a/example/regex_mas/main.cc Sun Dec 22 11:59:03 2013 +0900 +++ b/example/regex_mas/main.cc Sun Dec 22 18:53:03 2013 +0900 @@ -26,8 +26,10 @@ int use_task_array = 1; int use_task_creater = 0; int use_compat = 0; +int div_read = 0; int array_task_num = 8; int spe_num = 1; +int DIVISION_SIZE = 4*4096; unsigned char *sword = 0; int task_count = 0; @@ -49,6 +51,19 @@ off_t size; } st_mmap_t; +typedef struct fileread { + struct filesize *self; + long fd; + long division_size; + long task_number; + long task_num; + long filesize; + long left_size; + int task_blocks; + char *read_text; + CPU_TYPE cpu; +} Fileread, *FilereadPtr; + /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ static int fix_byte(int size,int fix_byte_size) @@ -58,6 +73,76 @@ return size; } +SchedDefineTask1(RUN_READ_BLOCKS,read_run16); + +static int +read_run16(SchedTask *manager, void *in, void *out) { + + FilereadPtr fr = (FilereadPtr)in; + HTaskPtr wait; + + for (int i = 0; (fr->left_size > 0) && (i < fr->task_blocks); i++) { + HTaskPtr read = manager->create_task(TASK_READ); + read->set_cpu(fr->cpu); + + if (i == fr->task_blocks / 2) wait = read; + + read->set_param(0,(long)fr->task_number); //生成するTaskが何番目か + read->set_param(1,(long)fr->division_size); //1つのタスクが読み込む量 + if(fr->left_size <= fr->division_size){ + read->set_param(2,(long)fr->left_size); + }else{ + read->set_param(2,(long)fr->division_size); + } + read->set_param(3,(long)fr->fd); //fdの番号の受け渡し + + read->set_outData(0,fr->read_text + fr->division_size*fr->task_number, fr->division_size); + read->spawn(); + + fr->left_size -= fr->division_size; + fr->task_number++; + } + + if (fr->left_size > 0) { + HTaskPtr next = manager->create_task(RUN_READ_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0); + next->wait_for(wait); + next->spawn(); + } + return 0; +} + +static st_mmap_t +divide_read(TaskManager *manager,char *filename, FilereadPtr fr) +{ + long fd = (long)manager->allocate(sizeof(long)); + struct stat *sb = (struct stat*)manager->allocate(sizeof(struct stat)); + + 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); + } + + fr->fd = fd; + fr->cpu = spe_cpu; + fr->task_blocks = 16; + fr->filesize = sb->st_size; + fr->left_size = fr->filesize; + fr->division_size = 1024 * division; + fr->task_num = fr->filesize / 1024 * division; + fr->task_num += ((fr->filesize % 1024 * division) != 0); + + printf("filesize : %ld\n",fr->filesize); + printf("one_task_size: %ld\n",fr->division_size); + printf("task_num : %ld\n",fr->task_num); + + HTaskPtr run = manager->create_task(RUN_READ_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0); + run->spawn(); + + return fr->read_text; +} static st_mmap_t my_read(TaskManager *manager,char *filename) @@ -162,10 +247,10 @@ * 二つ実行されていて、Task が足りなくなることがないようにしている。 */ -SchedDefineTask1(RUN_TASK_BLOCKS,run16); +SchedDefineTask1(RUN_TASK_BLOCKS,task_run16); static int -run16(SchedTask *manager, void *in, void *out) +task_run16(SchedTask *manager, void *in, void *out) { WordCount *w = *(WordCount **)in; @@ -213,11 +298,18 @@ run_start(TaskManager *manager, char *filename,unsigned char *search_word, int search_word_len) { HTaskPtr t_print; + WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); + FilereadPtr fr = (FilereadPtr)manager->allocate(sizeof(FilereadPtr)); st_mmap_t st_mmap; - //st_mmap = my_mmap(filename); - st_mmap = my_read(manager,filename); - WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); + if (div_read != 0) { + st_mmap = divide_read(manager,filename,fr); + printf("in divide read\n"); + }else { + st_mmap = my_read(manager,filename); + printf("in my read\n"); + } + // bzero(w,sizeof(WordCount)); /* prepare BMSearch*/ @@ -302,6 +394,8 @@ } else if (strcmp(argv[i], "-c") == 0) { use_task_array = 0; use_compat = 1; + } else if (strcmp(argv[i], "-dr") == 0) { + div_read = 1; } else if (strcmp(argv[i], "-s") == 0) { use_task_array = 0; use_compat = 0;
--- a/example/regex_mas/task_init.cc Sun Dec 22 11:59:03 2013 +0900 +++ b/example/regex_mas/task_init.cc Sun Dec 22 18:53:03 2013 +0900 @@ -8,6 +8,7 @@ #endif SchedExternTask(Print); SchedExternTask(RUN_TASK_BLOCKS); +SchedExternTask(RUN_READ_BLOCKS); /** * この関数は ../spe/spe-main と違って @@ -25,4 +26,5 @@ SchedRegisterTask(TASK_PRINT, Print); SchedRegister(RUN_TASK_BLOCKS); + SchedRegister(RUN_READ_BLOCKS); }