changeset 2048:6796d85f3d6b draft

remove error
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 28 Jan 2016 00:05:49 +0900
parents de89da997e07
children 674ac7887dae
files TaskManager/ManyCore/FileMapReduce.cc TaskManager/ManyCore/FileMapReduce.h
diffstat 2 files changed, 92 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/ManyCore/FileMapReduce.cc	Wed Jan 27 19:09:33 2016 +0900
+++ b/TaskManager/ManyCore/FileMapReduce.cc	Thu Jan 28 00:05:49 2016 +0900
@@ -2,17 +2,12 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/time.h>
-#include "TaskManager.h"
+#include <sys/mman.h>
 #include "SchedTask.h"
-#include "Func.h"
-#include "WordCount.h"
 
 /* ;TODO
  * PS3でCPU数が2以上の時に、あまりが計算されてない
@@ -20,8 +15,6 @@
 
 extern void task_init();
 void TMend(TaskManager *);
-static double st_time;
-static double ed_time;
 int all = 0;
 int use_task_array = 1;
 int use_task_creater = 0;
@@ -36,20 +29,44 @@
 
 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-g] [-file filename] [-br]\n";
 
-static double
-getTime() {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return tv.tv_sec + (double)tv.tv_usec*1e-6;
+FileMapReduce::FileMapReduce(TaskManager *manager,const char* filename,int TASK_EXEC,int TASK_PRINT) {
+    task_init();
 }
 
-typedef struct {
-    caddr_t file_mmap;
-    off_t size;
-} st_mmap_t;
+#ifdef __CERIUM_GPU__
+#include "GpuScheduler.h"
+#endif
+#ifdef __CERIUM_CUDA__
+#include "CudaScheduler.h"
+#endif
+
+/* 必ずこの位置に書いて */
+SchedExternTask(READ_TASK);
+SchedExternTask(BREAD_RUN_TASK_BLOCKS);
+SchedExternTask(Exec);
+SchedExternTask(Print);
+SchedExternTask(RUN_TASK_BLOCKS);
+void
+task_init(void)
+{
+#ifdef __CERIUM_GPU__
+    GpuSchedRegister(TASK_EXEC, "gpu/Exec.cl", "wordcount");
+#endif
+#ifdef __CERIUM_CUDA__
+    CudaSchedRegister(TASK_EXEC, "cuda/Exec.ptx", "wordcount");
+#endif
+
+    SchedRegisterTask(TASK_EXEC, Exec);
+
+    SchedRegister(READ_TASK);
+    SchedRegister(BREAD_RUN_TASK_BLOCKS);
+
+    SchedRegisterTask(TASK_PRINT, Print);
+    SchedRegister(RUN_TASK_BLOCKS);
+}
 
 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/
-static int 
+static int
 fix_byte(int size,int fix_byte_size)
 {
     size = (size/fix_byte_size)*fix_byte_size  + ((size%fix_byte_size)!= 0)*fix_byte_size;
@@ -85,8 +102,6 @@
         perror(NULL);
         exit(0);
     }
-
-    return ;
 }
 
 static void
@@ -108,7 +123,6 @@
 
     st_mmap.size = fix_byte(sb.st_size,4096);
 
-    //madvise(w->file_mmap, w->read_filesize, POSIX_MADV_NORMAL);
     w->file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0);
 
     if (st_mmap.file_mmap == (caddr_t)-1) {
@@ -116,14 +130,11 @@
         perror(NULL);
         exit(0);
     }
-
-    return ;
 }
 
 static void
 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_read, HTaskPtr t_next, int size)
 {
-
     if (task_count < array_task_num) {
         array_task_num = task_count;
         if (task_count<=0) return;
@@ -164,16 +175,13 @@
                 t_exec->set_param(3,(long)w->division_out_size);
                 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);
                 h_exec->spawn();
             } else if (use_iterate) {
                 array_task_num = w->task_num;
                 use_iterate = 0;
                 use_compat = 1;
-                
                 w->size -= size*array_task_num;
                 if(w->size < 0) {
                     array_task_num -= 1;
@@ -189,14 +197,11 @@
                 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_spawned += array_task_num-1;
-                
                 break;
             } else {
                 h_exec = manager->create_task(TASK_EXEC,
@@ -302,7 +307,6 @@
 }
 
 static int blocks = 48;
-//static int blocks = 31 * 6 * 24;
 static int division = 16; // in Kbyte
 
 static void
--- a/TaskManager/ManyCore/FileMapReduce.h	Wed Jan 27 19:09:33 2016 +0900
+++ b/TaskManager/ManyCore/FileMapReduce.h	Thu Jan 28 00:05:49 2016 +0900
@@ -1,4 +1,60 @@
+#include <sys/types.h>
+
+#include "TaskManager.h"
+
+typedef struct wordCount {
+    struct wordCount *self;
+    long fd;
+    long read_filesize;
+    CPU_TYPE read_cpu;
+
+    long size;             // remaining file size
+    long division_size;    // for each word count task
+    long division_out_size;
+    long out_size;
+    long out_size_;
+    long task_num;         // remaining task count
+    long task_blocks;      // spawn task one at a time
+    long status_num;
+    long task_spawned;
+    unsigned long long *o_data;
+    unsigned long long *head_tail_flag;
+    long out_task_num;
+    long pad;
+    char *file_mmap;
+    long file_size;
+    HTaskPtr t_print;
+    HTaskPtr t_exec;
+} WordCount, *WordCountPtr;
+
+enum {
+#include "SysTasks.h"
+    BREAD_RUN_TASK_BLOCKS,
+    READ_TASK,
+    TASK_EXEC,
+    RUN_TASK_BLOCKS,
+    TASK_PRINT,
+};
+
+// Read Type
+enum {
+    MY_MMAP,
+    MY_READ,
+    BLOCKED_READ,
+    BLOCKED_MMAP,
+};
+
+#define DATA_NUM 16
+#define ADD_NUM 26
+
+#define DATA_ID 0
+
+typedef struct {
+    caddr_t file_mmap;
+    off_t size;
+} st_mmap_t;
+
 class FileMapReduce {
     FileMapReduce(TaskManager *manager,const char* filename,int TASK_EXEC,int TASK_PRINT);
     void start();
-}
+};