changeset 1911:f842ea419307 draft

running mmap mode ( cannot running divide read )
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Sun, 19 Jan 2014 23:36:02 +0900
parents b7b528e9ec5e
children 4a716f35980a
files example/word_count/main.cc
diffstat 1 files changed, 21 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/example/word_count/main.cc	Sun Jan 19 22:54:01 2014 +0900
+++ b/example/word_count/main.cc	Sun Jan 19 23:36:02 2014 +0900
@@ -31,6 +31,7 @@
 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
@@ -112,7 +113,7 @@
     st_mmap_t st_mmap;
 
     int fd = w->fd;
-    st_mmap.size = w->read_filesize;
+    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);
     if (st_mmap.file_mmap == (caddr_t)-1) {
         fprintf(stderr,"Can't mmap file\n");
@@ -164,12 +165,12 @@
 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) {
@@ -182,7 +183,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++) {
@@ -198,7 +199,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);
@@ -218,14 +219,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();
@@ -237,7 +238,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);
@@ -294,7 +295,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();
@@ -328,7 +329,7 @@
 
     w->self = w;
     w->fd = fd;
-    w->read_cpu = spe_cpu;
+    w->read_cpu = read_spe_cpu;
     w->read_task_blocks = 16;
     w->read_filesize = sb->st_size;
     w->read_left_size = w->read_filesize;
@@ -340,33 +341,31 @@
     printf("one_task_size: %d\n",w->read_division_size);
     printf("task_num     : %d\n",w->read_task_num);
 
-    HTaskPtr run = NULL;
+    HTaskPtr r_run = NULL;
 
     if (divide_read_flag != 0) {
         char *read_text = (char*)manager->allocate(w->read_filesize);
-        run = manager->create_task(RUN_READ_BLOCKS, (memaddr)&w->self, sizeof(memaddr),read_text,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);
-        run = manager->create_task(MMAP , (memaddr)&w->self, sizeof(memaddr),0,0);
+        r_run = manager->create_task(MMAP , (memaddr)&w->self, sizeof(memaddr),0,0);
     }
 
-    run->spawn();
 
     /* original */
     HTaskPtr t_print;
 
     st_mmap_t st_mmap;
     //st_mmap = my_mmap(filename);
-    // bzero(w,sizeof(WordCount));
 
     //w->task_blocks = blocks;
     w->self = w;
     w->task_spwaned = 0;
 
     /*sizeはdivision_sizeの倍数にしている。*/
-    w->size = w->file_size = st_mmap.size;
-    w->file_mmap = st_mmap.file_mmap;
+    w->size = w->file_size = w->read_filesize;
+    //w->file_mmap = st_mmap.file_mmap;
     printf("w %lx\n",(long)w);
 
     /* 1task分のデータサイズ(byte) */
@@ -408,16 +407,19 @@
 
     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 されていると仮定する... */
         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();
 }