changeset 1824:016746241fc7 draft

fix fileread
author masakoha
date Sat, 14 Dec 2013 18:31:15 +0900
parents 8be14797e5ce
children 82c2b9eec625
files TaskManager/ChangeLog example/fileread/Func.h example/fileread/main.cc example/fileread/ppe/Print.cc example/fileread/ppe/Read.cc example/fileread/ppe/task_init.cc
diffstat 6 files changed, 76 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/ChangeLog	Fri Dec 13 20:46:46 2013 +0900
+++ b/TaskManager/ChangeLog	Sat Dec 14 18:31:15 2013 +0900
@@ -1,3 +1,9 @@
+2013-12-14 Masataka Kohagura <kohagura@ie.u-ryukyu.ac.jp>
+
+	fileを分割してmap reduce を行うAPIを作成する。
+	mapreduce(const char *filename , long division_size, int task_blocks,
+		int map_cmd, int reduce_cmd, long size_param);
+
 2013-12-12 Shohei KOKUBO <kokubo@ie.u-ryukyu.ac.jp>
 
 	現在の GpuScheduler の pipeline 実行は2並列(cur=0,1)
--- a/example/fileread/Func.h	Fri Dec 13 20:46:46 2013 +0900
+++ b/example/fileread/Func.h	Sat Dec 14 18:31:15 2013 +0900
@@ -1,6 +1,6 @@
 enum {
 #include "SysTasks.h"
-    READ_TASK,
-    PRINT_TASK,
+    Read_task,
+    Print_task,
 };
 
--- a/example/fileread/main.cc	Fri Dec 13 20:46:46 2013 +0900
+++ b/example/fileread/main.cc	Sat Dec 14 18:31:15 2013 +0900
@@ -18,6 +18,52 @@
 const char *usr_help_str = "Usage: ./fileread [-cpu cpu_num] [-file filename]\n\
                             -cpu    Number of SPE (default 1) \n\
                             -file   Opne file\n";
+typedef struct fileread {
+   struct filesize *self;
+   int fd;
+   long division_size;
+   long task_number;
+   long task_num;
+   long filesize;
+   long left_size;
+   int task_blocks;
+   CPU_TYPE cpu;
+} Fileread, *FilereadPtr;
+
+SchedDefineTask1(RUN_BLOCKS,run16);
+
+static int
+run16(SchedTask *m, void *in, void *out){
+    FilereadPtr fr = (FilereadPtr)in;
+    HTaskPtr wait;
+
+    for (int task_number = 0; fr->left_size > 0 && task_number < fr->task_blocks; task_number++) {
+        HTaskPtr read = manager->create_task(Read_task);
+        read->set_cpu(fr->spe_cpu);
+
+	if (task_number == 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);
+        read->spawn();
+
+        fr->left_size -= fr->division_size;
+    }
+
+    if (fr->left_size > 0) {
+    	HTaskPtr next = manager->create_task(RUN_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0);
+	next->wait_for(wait);
+	next->spawn();
+    }
+}
 
 static double
 getTime(){
@@ -60,45 +106,32 @@
 run_start(TaskManager *manager,char *filename)
 {
     HTask *read;
-    int *fd = (int*)manager->allocate(sizeof(int));
+    int fd;
 
     struct stat *sb = (struct stat*)manager->allocate(sizeof(struct stat));
 
-    if ((*fd=open(filename,O_RDONLY,0666))==0) {
+    if ((fd=open(filename,O_RDONLY,0666))==0) {
         fprintf(stderr,"can't open %s\n",filename); 
     }
 
-    if (fstat(*fd,sb)) {
+    if (fstat(fd,sb)) {
         fprintf(stderr,"can't fstat %s\n",filename);
     }
 
-    int filesize = sb->st_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",DIVISION_SIZE);
-    printf("task_num     : %d\n",task_num);
-
-    for(int task_number = 0; task_number < task_num; task_number++){
-        read = manager->create_task(READ_TASK);
-        read->set_cpu(spe_cpu);
+    FilereadPtr fr = (FilereadPtr)manager->allocate(sizeof(Fileread));
 
-        //ファイルディスクリプタをそのままタスクに渡してあげる
-        read->set_inData(0,fd,sizeof(int*));
+    fr->task_blocks = 16;
+    fr->filesize = sb->st_size;
+    fr->left_size = filesize;
+    fr->division_size = DIVISION_SIZE;
+    fr->task_num = fr->filesize / DIVISION_SIZE;
+    fr->task_num += ((fr->filesize % DIVISION_SIZE) != 0);
 
-        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);
-        }else{
-            read->set_param(2,(long)DIVISION_SIZE);
-        }
-        read->spawn();
+    printf("filesize     : %d\n",fr->filesize);
+    printf("one_task_size: %d\n",fr->DIVISION_SIZE);
+    printf("task_num     : %d\n",fr->task_num);
 
-        left_size -= DIVISION_SIZE;
-    }
+    HTaskPtr run = manager->create_task(RUN_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0);
 }
 
 
--- a/example/fileread/ppe/Print.cc	Fri Dec 13 20:46:46 2013 +0900
+++ b/example/fileread/ppe/Print.cc	Sat Dec 14 18:31:15 2013 +0900
@@ -4,10 +4,10 @@
 #include "Func.h"
 
 /* これは必須 */
-SchedDefineTask(Print);
+SchedDefineTask1(Print_task,print_task);
 
 static int
-run(SchedTask *smanager, void *rbuf, void *wbuf)
+print_task(SchedTask *smanager, void *rbuf, void *wbuf)
 {
     //int task_id = (long)smanager->get_param(0);
 
--- a/example/fileread/ppe/Read.cc	Fri Dec 13 20:46:46 2013 +0900
+++ b/example/fileread/ppe/Read.cc	Sat Dec 14 18:31:15 2013 +0900
@@ -11,10 +11,10 @@
 #include "Func.h"
 
 /* これは必須 */
-SchedDefineTask(Read);
+SchedDefineTask1(Read_task,read_task);
 
 static int
-run(SchedTask *s, void *rbuf, void *wbuf)
+read_task(SchedTask *s, void *rbuf, void *wbuf)
 {
     int *fd = (int *)s->get_input(rbuf,0);  ///ファイルディスクリプタの受取
 
--- a/example/fileread/ppe/task_init.cc	Fri Dec 13 20:46:46 2013 +0900
+++ b/example/fileread/ppe/task_init.cc	Sat Dec 14 18:31:15 2013 +0900
@@ -2,8 +2,8 @@
 #include "Scheduler.h"
 
 /* 必ずこの位置に書いて */
-SchedExternTask(Read);
-SchedExternTask(Print);
+SchedExternTask(Read_task);
+SchedExternTask(Print_task);
 
 /**
  * この関数は ../spe/spe-main と違って
@@ -14,6 +14,6 @@
 void
 task_init(void)
 {
-  SchedRegisterTask(READ_TASK, Read);
-  SchedRegisterTask(PRINT_TASK, Print);
+  SchedRegister(Read_task);
+  SchedRegister(Print_task);
 }