changeset 1786:ba6ffc679a8f draft

minor fix
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Sat, 30 Nov 2013 21:06:44 +0900
parents ae8e90890961
children 5cde37f02c66
files example/regex_mas/d.txt example/regex_mas/main.cc example/regex_mas/ppe/Exec.cc example/regex_mas/ppe/Print.cc
diffstat 4 files changed, 54 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/example/regex_mas/d.txt	Fri Nov 29 16:21:48 2013 +0900
+++ b/example/regex_mas/d.txt	Sat Nov 30 21:06:44 2013 +0900
@@ -80,4 +80,4 @@
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcd16380
-doingabaaabaaabab
+adoingabaaabaaabab
--- a/example/regex_mas/main.cc	Fri Nov 29 16:21:48 2013 +0900
+++ b/example/regex_mas/main.cc	Sat Nov 30 21:06:44 2013 +0900
@@ -36,10 +36,9 @@
  *                 (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 = 2;
+int set_param_num = 0;
 int set_out_num = 1;
 
 static int division = 16; // in Kbyte
@@ -103,113 +102,77 @@
 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 i = 0; i < task_count; i += array_task_num) {
 
-            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--;
-                }
+        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);
             }
-            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) {
-
+        Task *t_exec = 0;
         HTask *h_exec = 0;
         for (int j = 0; j < array_task_num; j++) {
-            int i = w->task_spwaned++;
+            int a = w->task_spwaned++;
             if (w->size < size) size = w->size;
-            int length = size/sizeof(char);
             if (size==0) break;
-
-            if (use_compat) {
+            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);
+                }
+                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);
-                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(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);
 
-                if (all) {
-                    w->t_print->wait_for(h_exec);
-                } else {
-                    t_next->wait_for(h_exec);
-                }
+                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);
-
-                if (all) {
-                    w->t_print->wait_for(h_exec);
-                } else {
-                    t_next->wait_for(h_exec);
-                }
-
+                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);
+        }
     }
-
 }
 
 /**
@@ -265,7 +228,7 @@
 }
 
 static void
-run_start(TaskManager *manager, char *filename,unsigned char *search_word)
+run_start(TaskManager *manager, char *filename,unsigned char *search_word,int search_word_len)
 {
     HTaskPtr t_print;
 
@@ -276,9 +239,9 @@
     // bzero(w,sizeof(WordCount));
 
     /* prepare BMSearch*/
-    int *skip = (int*)manager->allocate(sizeof(int)*256);
+    int *skip = (int*)manager->allocate(256);
     w->search_word = search_word;
-    w->search_word_len = strlen((const char*)w->search_word);
+    w->search_word_len = search_word_len;
     w->BMskip_table = create_BMskiptable(w->search_word, w->search_word_len, skip);
     w->extra_len = w->search_word_len - 1;
 
@@ -394,7 +357,8 @@
 
     task_init();
     st_time = getTime();
-    run_start(manager, filename,search_word);
+    run_start(manager, filename,search_word,sw_len);
+
     manager->set_TMend(TMend);
     return 0;
 }
--- a/example/regex_mas/ppe/Exec.cc	Fri Nov 29 16:21:48 2013 +0900
+++ b/example/regex_mas/ppe/Exec.cc	Sat Nov 30 21:06:44 2013 +0900
@@ -44,8 +44,11 @@
     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;
--- a/example/regex_mas/ppe/Print.cc	Fri Nov 29 16:21:48 2013 +0900
+++ b/example/regex_mas/ppe/Print.cc	Sat Nov 30 21:06:44 2013 +0900
@@ -16,10 +16,9 @@
     int match_counter = 0;
 
     for (int i = 0;i < idata_task_num;i++) {
-    
+
             match_counter += idata[i];
             //s->printf("idata[%d]=:%d\n",i,idata[i]);
-
     }
     s->printf("HIT:%d\n",match_counter);
     return 0;