changeset 1787:5cde37f02c66 draft

back main.cc
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Sun, 01 Dec 2013 16:48:27 +0900
parents ba6ffc679a8f
children 06f5a4b09396
files example/regex_mas/main.cc example/regex_mas/ppe/Exec.cc
diffstat 2 files changed, 90 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/example/regex_mas/main.cc	Sat Nov 30 21:06:44 2013 +0900
+++ b/example/regex_mas/main.cc	Sun Dec 01 16:48:27 2013 +0900
@@ -36,6 +36,7 @@
  *                 (TASK_EXEC,array_task_num,set_param_num,input_set_inData,1);
  * create_task_arrayの第四引数でset_inDataの数を指定させている。
  * これにメチャクチャハマったので注意
+ * いつかはcreate_task_arrayを消したい
  */
 int set_inData_num = 3;
 int set_param_num = 0;
@@ -102,77 +103,113 @@
 static void
 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size)
 {
-       if (task_count < array_task_num) {
+    if (task_count < array_task_num) {
         array_task_num = task_count;
         if (task_count<=0) return;
     }
 
+    if (use_task_array) {
+
+        int spl = spe_num * array_task_num;
+        int loop = (task_count + spl - 1) / spl;
+
+        for (int i = 0; i < loop; i += 1) {
+
+            if (w->task_num < spe_num) spe_num = w->task_num;
+
+            // ここから
+            HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num);
+            Task **t_exec = (Task**)manager->allocate(sizeof(Task*)*spe_num);
+
+            for (int k = 0; k < spe_num; k++) {
+                task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,set_param_num,set_inData_num,set_out_num);
+                t_exec[k] = 0;
+                if (all) {
+                    w->t_print->wait_for(task_array[k]);
+                } else {
+                    t_next->wait_for(task_array[k]);
+                }
+            }
+
+            for (int j = 0; j < array_task_num; j++) {
+                for (int k = 0; k < spe_num; k++) {
+                    int a = w->task_spwaned++;
+
+                    if (w->size < size) size = w->size;
+                    //if (size == w->size) break;
+
+                    t_exec[k] = task_array[k]->next_task_array(TASK_EXEC,t_exec[k]);
+
+                    if(size != w->size){ //最後のタスクかどうかの判定
+                        t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, w->division_size + w->extra_len);
+                    }else{
+                        t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, w->division_size);
+                    }
+                    t_exec[k]->set_inData(1,w->search_word, w->search_word_len);
+                    t_exec[k]->set_inData(2,w->BMskip_table, 256);
+
+                    t_exec[k]->set_outData(0,w->o_data + a*w->out_size, w->division_out_size);
+                    w->size -= size;
+                    w->task_num--;
+                }
+            }
+            for (int k = 0; k < spe_num; k++) {
+                task_array[k]->spawn_task_array(t_exec[k]->next());
+                task_array[k]->set_cpu(spe_cpu);
+                task_array[k]->spawn();
+            }
+
+        }
+
+        return;
+
+    }
+
     for (int i = 0; i < task_count; i += array_task_num) {
 
-        HTask *task_array;
-        if (use_task_array) {
-            int task_num = (w->size+size-1)/size;
-            if (task_num>array_task_num) task_num = array_task_num;
-            task_array = manager->create_task_array(TASK_EXEC,task_num,set_param_num,set_inData_num,set_out_num);
-            if (!all) {
-                t_next->wait_for(task_array);
-            } else {
-                w->t_print->wait_for(task_array);
-            }
-        }
-
-        Task *t_exec = 0;
         HTask *h_exec = 0;
         for (int j = 0; j < array_task_num; j++) {
-            int a = w->task_spwaned++;
+            int i = w->task_spwaned++;
             if (w->size < size) size = w->size;
+            int length = size/sizeof(char);
             if (size==0) break;
-            if (use_task_array) {
-                t_exec = task_array->next_task_array(TASK_EXEC,t_exec);
-                if(size != w->size){ //最後のタスクかどうかの判定
-                    t_exec->set_inData(0,w->file_mmap + a*w->division_size, w->division_size + w->extra_len);
-                }else{
-                    t_exec->set_inData(0,w->file_mmap + a*w->division_size, w->division_size);
+
+            if (use_compat) {
+                h_exec = manager->create_task(TASK_EXEC);
+                h_exec->set_param(0,&length);
+                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);
+
+
+                if (all) {
+                    w->t_print->wait_for(h_exec);
+                } else {
+                    t_next->wait_for(h_exec);
                 }
-                t_exec->set_inData(1,w->search_word, w->search_word_len);
-                t_exec->set_inData(2,w->BMskip_table, 256);
-                t_exec->set_outData(0,w->o_data + a*w->out_size, w->division_out_size);
-                w->size -= size;
-                w->task_num--;
-            } else if (use_compat) {
-                h_exec = manager->create_task(TASK_EXEC);
-                if(size != w->size){ //最後のタスクかどうかの判定
-                    t_exec->set_inData(0,w->file_mmap + a*w->division_size, w->division_size + w->extra_len);
-                }else{
-                    t_exec->set_inData(0,w->file_mmap + a*w->division_size, w->division_size);
-                }
-                t_exec->set_inData(1,w->search_word, w->search_word_len);
-                t_exec->set_inData(2,w->BMskip_table, 256);
-                t_exec->set_outData(0,w->o_data + a*w->out_size, w->division_out_size);
-
-                t_next->wait_for(h_exec);
 
                 h_exec->set_cpu(spe_cpu);
                 h_exec->spawn();
+
             } else {
                 h_exec = manager->create_task(TASK_EXEC,
                                               (memaddr)(w->file_mmap + i*w->division_size), size,
                                               (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
-                t_next->wait_for(h_exec);
+
+                if (all) {
+                    w->t_print->wait_for(h_exec);
+                } else {
+                    t_next->wait_for(h_exec);
+                }
+
                 h_exec->set_cpu(spe_cpu);
                 h_exec->spawn();
             }
             w->size -= size;
             w->task_num--;
         }
-        if (use_task_array) {
-            task_array->spawn_task_array(t_exec->next());
-            task_array->set_cpu(spe_cpu);
-            task_array->spawn();
-        } else {
-            //if (!all) t_next->wait_for(h_exec);
-        }
+
     }
+
 }
 
 /**
@@ -228,7 +265,7 @@
 }
 
 static void
-run_start(TaskManager *manager, char *filename,unsigned char *search_word,int search_word_len)
+run_start(TaskManager *manager, char *filename,unsigned char *search_word)
 {
     HTaskPtr t_print;
 
@@ -239,9 +276,9 @@
     // bzero(w,sizeof(WordCount));
 
     /* prepare BMSearch*/
-    int *skip = (int*)manager->allocate(256);
+    int *skip = (int*)manager->allocate(sizeof(int)*256);
     w->search_word = search_word;
-    w->search_word_len = search_word_len;
+    w->search_word_len = strlen((const char*)w->search_word);
     w->BMskip_table = create_BMskiptable(w->search_word, w->search_word_len, skip);
     w->extra_len = w->search_word_len - 1;
 
@@ -357,8 +394,7 @@
 
     task_init();
     st_time = getTime();
-    run_start(manager, filename,search_word,sw_len);
-
+    run_start(manager, filename,search_word);
     manager->set_TMend(TMend);
     return 0;
 }
--- a/example/regex_mas/ppe/Exec.cc	Sat Nov 30 21:06:44 2013 +0900
+++ b/example/regex_mas/ppe/Exec.cc	Sun Dec 01 16:48:27 2013 +0900
@@ -39,16 +39,14 @@
     int *skip_table = (int *)s->get_input(rbuf,2);
     int length = (int)s->get_inputSize(0);
     int sw_len = (int)s->get_inputSize(1);
-    //set_param
-    s->printf("length %d\n",length);
-    s->printf("sw_len %d\n",sw_len);
+
+    //s->printf("length %d\n",length);
+    //s->printf("sw_len %d\n",sw_len);
 
     unsigned long long *o_data = (unsigned long long*)wbuf;
     o_data[0] = 0;
 
-    s->printf("pre o_data :%d\n",o_data[0]);
     o_data[0] = BM_method(i_data,length,search_word,sw_len,skip_table);
-    s->printf("aft o_data :%d\n",o_data[0]);
 
     //s->printf("in Exec.cc\n");
     return 0;