changeset 1808:c25aa7edd1ba draft

fix conditional branch in fileread
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Wed, 11 Dec 2013 17:42:09 +0900
parents 8f7052d19157
children 138e7edff3ae
files example/fileread/d.txt example/fileread/main.cc example/fileread/ppe/Read.cc
diffstat 3 files changed, 25 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/example/fileread/d.txt	Tue Dec 10 19:14:48 2013 +0900
+++ b/example/fileread/d.txt	Wed Dec 11 17:42:09 2013 +0900
@@ -80,4 +80,4 @@
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcd16380
-doingabaaabaaabab
+doingxbaaabaaabab
--- a/example/fileread/main.cc	Tue Dec 10 19:14:48 2013 +0900
+++ b/example/fileread/main.cc	Wed Dec 11 17:42:09 2013 +0900
@@ -12,7 +12,7 @@
 static double ed_time;
 static int spe_num = 1;
 static CPU_TYPE spe_cpu = SPE_ANY;
-static int ONE_TASK_SIZE = 4096 * 4;
+static int DIVISION_SIZE = 4096 * 4;
 
 extern TaskManager *manager;
 const char *usr_help_str = "Usage: ./fileread [-cpu cpu_num] [-file filename]\n\
@@ -73,36 +73,32 @@
     }
 
     int filesize = sb->st_size;
-    int task_num = filesize / ONE_TASK_SIZE;
-    task_num += ((filesize % ONE_TASK_SIZE) != 0);
-    int last_task_size = filesize % ONE_TASK_SIZE;
+    int left_size = filesize;
+    int task_num = filesize / DIVISION_SIZE;
+    task_num += ((filesize % DIVISION_SIZE) != 0);
 
     printf("filesize     : %d\n",filesize);
-    printf("one_task_size: %d\n",ONE_TASK_SIZE);
+    printf("one_task_size: %d\n",DIVISION_SIZE);
     printf("task_num     : %d\n",task_num);
 
-    int task_number = 0;
-
-    for(task_number = 0; task_number < task_num - 1; task_number++){
+    for(int task_number = 0; task_number < task_num; task_number++){
         read = manager->create_task(READ_TASK);
         read->set_cpu(spe_cpu);
 
         //ファイルディスクリプタをそのままタスクに渡してあげる
-        read->set_inData(0,(memaddr)fd,sizeof(int*));
-        read->set_param(0,(long)ONE_TASK_SIZE);  //1つのタスクが読み込む量
-        read->set_param(1,(long)task_number);  //生成するTaskが何番目か
-        read->spawn();
-    }
+        read->set_inData(0,fd,sizeof(int*));
 
-    //Last case
-    read = manager->create_task(READ_TASK);
-    read->set_cpu(spe_cpu);
+        read->set_param(0,(long)task_number);  //生成するTaskが何番目か
+        read->set_param(1,(long)DIVISION_SIZE);  //1つのタスクが読み込む量
+        if(left_size <= DIVISION_SIZE){
+            read->set_param(2,(long)left_size);  //生成するTaskが何番目か
+        }else{
+            read->set_param(2,(long)DIVISION_SIZE);  //生成するTaskが何番目か
+        }
+        read->spawn();
 
-    //ファイルディスクリプタをそのままタスクに渡してあげる
-    read->set_inData(0,(memaddr)fd,sizeof(int*));
-    read->set_param(0,(long)last_task_size);  //1つのタスクが読み込む量
-    read->set_param(1,(long)task_number);  //生成するTaskが何番目か
-    read->spawn();
+        left_size -= DIVISION_SIZE;
+    }
 }
 
 
--- a/example/fileread/ppe/Read.cc	Tue Dec 10 19:14:48 2013 +0900
+++ b/example/fileread/ppe/Read.cc	Wed Dec 11 17:42:09 2013 +0900
@@ -18,19 +18,17 @@
 {
     int *fd = (int *)s->get_input(rbuf,0);  ///ファイルディスクリプタの受取
 
-    long readsize = (long)s->get_param(0);
-    long task_number = (long)s->get_param(1);
-
-    char text[(long)readsize];
+    long task_number = (long)s->get_param(0);   //何番目のtaskか
+    long division_size = (long)s->get_param(1);
+    long read_size = (long)s->get_param(2);
 
-    //lseekで読み込む場所を教えてあげる
-    //s->xはiteraterで繰り返した数
-    //lseek(*fd,readsize*task_number,SEEK_SET);
-    read(*fd,text,(long)readsize);
+    char text[(long)read_size];
+
+    lseek(*fd, division_size* task_number,SEEK_SET);   //lseekでどこから読み込むのか指定
+    read(*fd,text,(long)read_size);
 
     s->printf("[start task No. %d]\n",task_number);
     s->printf("%s\n",text);
-    //s->printf("[end task No. %d]\n",task_number);
 
     return 0;
 }