changeset 1913:53c074e60b08 draft

restore some files
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Mon, 20 Jan 2014 16:10:56 +0900
parents 4a716f35980a
children 08e9e416c2e0
files example/word_count/Func.h example/word_count/main.cc example/word_count/task_init.cc
diffstat 3 files changed, 37 insertions(+), 133 deletions(-) [+]
line wrap: on
line diff
--- a/example/word_count/Func.h	Mon Jan 20 03:39:03 2014 +0900
+++ b/example/word_count/Func.h	Mon Jan 20 16:10:56 2014 +0900
@@ -1,8 +1,5 @@
 enum {
 #include "SysTasks.h"
-    Read_task,
-    RUN_READ_BLOCKS,
-    MMAP,
     TASK_EXEC,
     TASK_EXEC_DATA_PARALLEL,
     RUN_TASK_BLOCKS,
--- a/example/word_count/main.cc	Mon Jan 20 03:39:03 2014 +0900
+++ b/example/word_count/main.cc	Mon Jan 20 16:10:56 2014 +0900
@@ -28,10 +28,7 @@
 int use_iterate_all = 0;
 int array_task_num = 8;
 int spe_num = 1;
-int divide_read_flag = 0;
-int READ_DIVISION_SIZE = 16 * 1024;
 CPU_TYPE spe_cpu = SPE_ANY;
-CPU_TYPE read_spe_cpu = IO_0;
 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-g] [-file filename]\n";
 
 static double
@@ -56,87 +53,51 @@
 }
 
 
-SchedDefineTask1(RUN_READ_BLOCKS,read_run);
-
-static int
-read_run(SchedTask *manager, void *in, void *out) {
-
-    WordCountPtr w = (WordCountPtr)in;
-    char* read_text = (char*)out;
-    HTaskPtr wait;
-
-    for (int i = 0; (w->read_left_size > 0) && (i < w->read_task_blocks); i++) {
-        HTaskPtr read = manager->create_task(Read_task);
-        read->set_cpu(w->read_cpu);
-
-        if (i == w->read_task_blocks / 2) wait = read;
+static st_mmap_t
+my_mmap(char *filename)
+{
 
-        read->set_param(0,(long)w->read_task_number);  //生成するTaskが何番目か
-        read->set_param(1,(long)w->read_division_size);  //1つのタスクが読み込む量
-        if(w->read_left_size <= w->read_division_size){
-            read->set_param(2,(long)w->read_left_size);
-        }else{
-            read->set_param(2,(long)w->read_division_size);
-        }
-        read->set_param(3,(long)w->fd);  //fdの番号の受け渡し
+    /*マッピングだよ!*/
+    int fd = -1;
+    int map = MAP_PRIVATE;
+    st_mmap_t st_mmap;
+    struct stat sb;
 
-        read->set_outData(0,read_text + w->read_task_number*w->read_division_size, w->read_division_size);
-
-        w->t_print->wait_for(w->t_exec);
-        w->t_exec->wait_for(read);
-        read->spawn();
-
-        w->read_left_size -= w->read_division_size;
-        w->read_task_number++;
+    if ((fd=open(filename,O_RDONLY,0666))==0) {
+        fprintf(stderr,"can't open %s\n",filename);
     }
 
-    if (w->read_left_size > 0) {
-
-        HTaskPtr next = manager->create_task(RUN_READ_BLOCKS, (memaddr)&w->self, sizeof(memaddr),read_text,w->read_filesize);
+    if (fstat(fd,&sb)) {
+        fprintf(stderr,"can't fstat %s\n",filename);
+    }
 
-        w->t_print->wait_for(next);
-        w->t_exec->wait_for(next);
-        next->wait_for(wait);
-        next->spawn();
-    }
-    return 0;
-}
-
-SchedDefineTask1(MMAP,my_mmap);
+    printf("file size %d\n",(int)sb.st_size);
 
-static int
-my_mmap(SchedTask *s, void *in, void *out)
-{
-
-    WordCountPtr w = (WordCountPtr)in;
-    /*マッピングだよ!*/
+    /*sizeをページングサイズの倍数にあわせる*/
+    st_mmap.size = fix_byte(sb.st_size,4096);
 
-    int map = MAP_PRIVATE;
-    st_mmap_t st_mmap;
-
-    int fd = w->fd;
-    st_mmap.size = fix_byte(w->read_filesize,4096);
-    w->file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0);
+    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) {
         fprintf(stderr,"Can't mmap file\n");
-
         perror(NULL);
         exit(0);
     }
 
-    printf("in mmap mode\n");
-    return 0;
+    return st_mmap;
+
 }
 
 static void
 run_tasks(SchedTask *manager, WordCount *w, int task_count, 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) {
@@ -149,7 +110,7 @@
                 w->t_print->wait_for(task_array);
             }
         }
-
+    
         Task *t_exec = 0;
         HTask *h_exec = 0;
         for (int j = 0; j < array_task_num; j++) {
@@ -165,7 +126,7 @@
                 h_exec = manager->create_task(TASK_EXEC);
                 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
                 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
-
+                
                 t_next->wait_for(h_exec);
 
                 h_exec->set_cpu(spe_cpu);
@@ -185,14 +146,14 @@
                 h_exec->set_param(1,(long)w->division_size);
                 h_exec->set_param(2,(long)size);
                 h_exec->set_param(3,(long)w->out_size);
-
+                
                 t_next->wait_for(h_exec);
                 h_exec->set_cpu(spe_cpu);
                 h_exec->iterate(array_task_num);
-
+                
                 w->task_num -= array_task_num;
                 w->task_spwaned += array_task_num-1;
-
+                
                 if(w->size < 0) {
                     h_exec = manager->create_task(TASK_EXEC_DATA_PARALLEL);
                     h_exec->flip();
@@ -204,7 +165,7 @@
                     h_exec->set_param(1,(long)w->division_size);
                     h_exec->set_param(2,(long)(size+w->size));
                     h_exec->set_param(3,(long)w->out_size);
-
+                    
                     t_next->wait_for(h_exec);
                     h_exec->set_cpu(spe_cpu);
                     h_exec->iterate(1);
@@ -261,7 +222,7 @@
         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);
 
         t_next->spawn();
@@ -278,62 +239,20 @@
 static void
 run_start(TaskManager *manager, char *filename)
 {
-
-    long   fd = (long)manager->allocate(sizeof(long));
-    struct stat *sb = (struct stat*)manager->allocate(sizeof(struct stat));
-    HTaskPtr t_exec = NULL;
-
-    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);
-    }
-
-    //WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
-    WordCountPtr w = (WordCountPtr)manager->allocate(sizeof(WordCount));
-
-    w->self = w;
-    w->fd = fd;
-    w->read_cpu = read_spe_cpu;
-    w->read_task_blocks = 16;
-    w->read_filesize = sb->st_size;
-    w->read_left_size = w->read_filesize;
-    w->read_division_size = READ_DIVISION_SIZE;
-    w->read_task_num = w->read_filesize / READ_DIVISION_SIZE;
-    w->read_task_num += ((w->read_filesize % READ_DIVISION_SIZE) != 0);
-    w->t_exec = t_exec;
-
-    printf("filesize     : %d\n",w->read_filesize);
-    printf("one_task_size: %d\n",w->read_division_size);
-    printf("task_num     : %d\n",w->read_task_num);
-
-    HTaskPtr r_run = NULL;
-
-    if (divide_read_flag != 0) {
-        char *read_text = (char*)manager->allocate(w->read_filesize);
-        r_run = manager->create_task(RUN_READ_BLOCKS, (memaddr)&w->self, sizeof(memaddr),read_text,w->read_filesize);
-        w->read_text = read_text;
-    }else {
-        //my_mmap(filename, fd, fr);
-        r_run = manager->create_task(MMAP , (memaddr)&w->self, sizeof(memaddr),0,0);
-    }
-
-
-    /* original */
     HTaskPtr t_print;
 
     st_mmap_t st_mmap;
-    //st_mmap = my_mmap(filename);
+    st_mmap = my_mmap(filename);
+    WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
+    // bzero(w,sizeof(WordCount));
 
     //w->task_blocks = blocks;
     w->self = w;
     w->task_spwaned = 0;
 
     /*sizeはdivision_sizeの倍数にしている。*/
-    w->size = w->file_size = w->read_filesize;
-    //w->file_mmap = st_mmap.file_mmap;
+    w->size = w->file_size = st_mmap.size;
+    w->file_mmap = st_mmap.file_mmap;
     printf("w %lx\n",(long)w);
 
     /* 1task分のデータサイズ(byte) */
@@ -375,20 +294,16 @@
 
     t_print = manager->create_task(TASK_PRINT,
                                    (memaddr)&w->self,sizeof(memaddr),0,0);
-    w->t_print = t_print;
-
+    w->t_print = t_print;    
     for(int i=0;i<1;i++) {
         /* Task を task_blocks ずつ起動する Task */
         /* serialize されていると仮定する... */
-        t_exec = manager->create_task(RUN_TASK_BLOCKS,
+        HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
                                                (memaddr)&w->self,sizeof(memaddr),0,0);
-        t_exec->wait_for(r_run);
         t_print->wait_for(t_exec);
         //    t_exec->iterate(4);
         t_exec->spawn();
     }
-    t_print->wait_for(r_run);
-    r_run->spawn();
     t_print->spawn();
 }
 
@@ -434,8 +349,6 @@
             use_iterate_all = 1;
             use_iterate = 1;
             use_task_array = 0;
-        } else if (strcmp(argv[i], "-dr") == 0) {
-            divide_read_flag = 1;
         } /* else if (strcmp(argv[i], "-cpu") == 0) {
             spe_num = atoi(argv[i+1]);
             i++;
--- a/example/word_count/task_init.cc	Mon Jan 20 03:39:03 2014 +0900
+++ b/example/word_count/task_init.cc	Mon Jan 20 16:10:56 2014 +0900
@@ -5,9 +5,6 @@
 #endif
 
 /* 必ずこの位置に書いて */
-SchedExternTask(Read_task);
-SchedExternTask(RUN_READ_BLOCKS);
-SchedExternTask(MMAP);
 SchedExternTask(Exec);
 SchedExternTask(Exec_Data_Parallel);
 SchedExternTask(Print);
@@ -25,9 +22,6 @@
     GpuSchedRegister(TASK_EXEC, "gpu/Exec.cl", "wordcount");
     GpuSchedRegister(TASK_EXEC_DATA_PARALLEL, "gpu/Exec_Data_Parallel.cl","wordcount_parallel");
 #endif
-    SchedRegister(Read_task);
-    SchedRegister(RUN_READ_BLOCKS);
-    SchedRegister(MMAP);
     SchedRegisterTask(TASK_EXEC, Exec);
     SchedRegisterTask(TASK_EXEC_DATA_PARALLEL, Exec_Data_Parallel);