changeset 281:b74e3b4b11d7

parallel search done
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Sun, 31 Jan 2016 18:28:58 +0900
parents 6bbd1cbf90d0
children 87a801c14117
files regexParser/cerium/CeriumMain.cc regexParser/cerium/ppe/Exec.cc regexParser/cerium/ppe/Print.cc regexParser/regexParser.h regexParser/threadedSearch.cc regexParser/threadedSearch.h
diffstat 6 files changed, 33 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/regexParser/cerium/CeriumMain.cc	Sun Jan 31 16:59:43 2016 +0900
+++ b/regexParser/cerium/CeriumMain.cc	Sun Jan 31 18:28:58 2016 +0900
@@ -36,6 +36,7 @@
 static
 TSValue stateMatch(TSValue tsv) {
     ResultPtr r = NEW(Result);
+    r->continued = false;
     r->begin = tsv.buff.matchBegin;
     r->end = tsv.buff.buffptr;
     *tsv.resultEnd = r;
@@ -51,7 +52,7 @@
     ResultPtr prev = NULL;
     // printf("%s\n",comment);
     for (;r;r = r->next) {
-        if (r->end == NULL) {
+        if (r->continued) {
             prev = r;
             break;
         }
--- a/regexParser/cerium/ppe/Exec.cc	Sun Jan 31 16:59:43 2016 +0900
+++ b/regexParser/cerium/ppe/Exec.cc	Sun Jan 31 18:28:58 2016 +0900
@@ -20,22 +20,27 @@
         tsv.current = tg->anyState->tState;
     }
     tsv.result = NULL;
-    tsv.resultEnd = &tsv.result;
-    unsigned char *end = buff.buffend;
-    buff.buffend = buff.buff+1;
-    tSearch(tsv);
+    ResultPtr result = NULL;
+    tsv.resultEnd = &result;
+    unsigned char *end = tsv.buff.buffend;
+    tsv.buff.buffend = tsv.buff.buff+1;
+    tsv = tSearch(tsv);
     tsv.blockBegin = tsv.current;
-    buff.buffend = end;
-    tSearch(tsv);
+    tsv.buff.buffend = end;
+    tsv = tSearch(tsv);
     tsv.blockEnd = tsv.current;
     if (tsv.blockEnd->state->bitState.bitContainer != 1) {
+        // partial match case at block end.
         ResultPtr r = NEW(Result);
+        r->continued = true;
         r->begin = tsv.buff.matchBegin;
-        r->end = NULL;
+        r->end = tsv.buff.buffptr-1;
         *tsv.resultEnd = r;
         r->next = NULL;
         tsv.resultEnd = &r->next;
+// printf("Exec %lx r->begin : %p r->end : %p\n",tsv.blockEnd->state->bitState.bitContainer, r->begin,r->end);
     }
+    tsv.result = result;
     return tsv;
 }
 
@@ -62,7 +67,7 @@
     buff.buff = buff.buffptr = buff.matchBegin = i_data;
     buff.buffend = buff.buff + length;
     TSValue tsv = blockSearch(tg,buff,task_spawned);
-    resultPrint(tsv.result,"Exec");
+//    resultPrint(tsv.result,"Exec");
     o_data[0] = (unsigned long)tsv.result;
     o_data[1] = (unsigned long)tsv.blockBegin->state;
     o_data[2] = (unsigned long)tsv.blockEnd->state;
--- a/regexParser/cerium/ppe/Print.cc	Sun Jan 31 16:59:43 2016 +0900
+++ b/regexParser/cerium/ppe/Print.cc	Sun Jan 31 18:28:58 2016 +0900
@@ -20,13 +20,25 @@
     ResultPtr prev = NULL;
     for (int i = 0; i < out_task_num ; i++) {
         ResultPtr r = (ResultPtr)w->o_data[i*out_size+0];
+        if (r == NULL) {
+            prev = NULL;
+            continue;
+        }
         StatePtr blockEnd = (StatePtr)w->o_data[i*out_size+2];
         StatePtr blockBegin = (StatePtr)w->o_data[i*out_size+4]; // next Block's blockBegin.
-        if (prev && i != out_task_num-1) {
+        if (prev) {
+            if (i >= out_task_num) break; 
             // 最後のブロックでなく、前の blockEnd が state 1 でない場合)
+#if 0
+printf("task %d prev begin : %p r->begin : %p r->end : %p\n", i,prev->begin,r->begin,r->end);
+printf("blockBegin : %lx blockEnd : %lx : string ",blockBegin->bitState.bitContainer,blockEnd->bitState.bitContainer);
+fwrite(r->begin,r->end - r->begin-1,1,stdout);
+printf(" match %d\n", ((blockBegin->bitState.bitContainer & ~blockEnd->bitState.bitContainer)==0)? 1 : 0  );
+#endif
             if ((blockBegin->bitState.bitContainer & ~blockEnd->bitState.bitContainer)==0) {
                 // 前のブロックの matchBegin から最初 result の end までがマッチ
-                fwrite(prev->begin,r->end - prev->begin,1,stdout);
+                fwrite(prev->begin,r->end - prev->begin-1,1,stdout);
+                if (!r->continued) puts("");
             }
             r = r->next;
         }
--- a/regexParser/regexParser.h	Sun Jan 31 16:59:43 2016 +0900
+++ b/regexParser/regexParser.h	Sun Jan 31 18:28:58 2016 +0900
@@ -69,6 +69,7 @@
 typedef struct result {
     unsigned char *begin;
     unsigned char *end;
+    bool continued;
     struct result *next;
 } Result, *ResultPtr;
 
--- a/regexParser/threadedSearch.cc	Sun Jan 31 16:59:43 2016 +0900
+++ b/regexParser/threadedSearch.cc	Sun Jan 31 18:28:58 2016 +0900
@@ -5,8 +5,6 @@
 #include "threadedSearch.h"
 #include "subsetConstruction.h"
 
-void tSearch(TSValue tsv);
-
 static
 TSValue stateNothing(TSValue tsv) {
     return tsv;
@@ -82,7 +80,7 @@
     return state->tState;
 }
 
-void tSearch(TSValue tsv) {
+TSValue tSearch(TSValue tsv) {
     next: while (tsv.buff.buffptr < tsv.buff.buffend) {
         unsigned char c = *tsv.buff.buffptr++;
         // printState(tsv.current->state);
@@ -109,6 +107,7 @@
         }
         tsv = tsv.current->stateSkip(tsv);
     }
+    return tsv;
 }
 
 void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) {
--- a/regexParser/threadedSearch.h	Sun Jan 31 16:59:43 2016 +0900
+++ b/regexParser/threadedSearch.h	Sun Jan 31 18:28:58 2016 +0900
@@ -1,3 +1,3 @@
 extern void threadedSearch(TransitionGeneratorPtr tg, Buffer buff);
 extern TStatePtr generateTState(StatePtr s, TransitionGeneratorPtr tg);
-void tSearch(TSValue tsv);
+TSValue tSearch(TSValue tsv);