view regexParser/cerium/ppe/Print.cc @ 302:27414e6fb33c

retrying blocked search fix for CbC support
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 08 Feb 2016 08:59:38 +0900
parents c5a7caa37f61
children cc770cd8d000
line wrap: on
line source

#include <stdio.h>
#include <string.h>
#include "Print.h"
#include "Func.h"
#include "FileMapReduce.h"
#include "regexParser.h"
#include "CeriumMain.h"
#include "threadedSearch.h"

#define STATUS_NUM 2
/* これは必須 */
SchedDefineTask1(Print,run_print);

static
TSValue stateSkipOnce(TSValue tsv) {
    if (tsv.matchEnd) {
        addResult(tsv,false,tsv.matchBegin,tsv.matchEnd);
    }
    tsv.buff.buffend = tsv.buff.buffptr;    // end search
    return tsv;
}


static int
run_print(SchedTask *s, void *rbuf, void *wbuf)
{
    MapReduce *w = (MapReduce*)s->get_input(0);
    
    int out_size = w->division_out_size / sizeof(unsigned long long);
    int out_task_num = w->task_num;
    ResultPtr prev = NULL;
    for (int i = 0; i < out_task_num ; i++) {
        ResultPtr r = (ResultPtr)w->o_data[i*out_size+0];
        //  first reply contains block begin and block end
        unsigned char *begin = r->begin;
        unsigned char *end = r->end;
        r = r->next;
        if (r == NULL) {
            prev = NULL;
            continue;
        }
        StatePtr blockBegin = (StatePtr)w->o_data[i*out_size+1];
        if (prev) {
            if (i >= out_task_num) break; 
            // 最後のブロックでなく、前の prevBlockEnd が state 1 でない場合)
            StatePtr prevBlockEnd = (StatePtr)w->o_data[i*out_size-1];
#if 0
printf("task %d prev begin : %p r->begin : %p r->end : %p\n", i,prev->begin,r->begin,r->end);
printf("nextblockBegin : %lx prevBlockEnd : %lx : string ",blockBegin->bitState.bitContainer,prevBlockEnd->bitState.bitContainer);
fwrite(r->begin,r->end - r->begin-1,1,stdout);
printf(" match %d\n", ((prevBlockEnd->bitState.bitContainer & ~blockBegin->bitState.bitContainer)==0)? 1 : 0  );
#endif
            if (prevBlockEnd->bitState.bitContainer !=1) {
                // そこから最初の stateSkip までやり直し。マッチしたら表示。
                TransitionGeneratorPtr tg = (TransitionGeneratorPtr)w->global;
                tg->stateSkip = stateSkipOnce;
                Buffer buff;
                buff.buff = buff.buffptr  = begin;
                buff.buffend = end;
                TSValue tsv = createTSValue(tg,buff);
                BlockOutput blk;
                tsv.blk = &blk;
                tsv.current = prevBlockEnd->tState;
                tsv.blk->result = NULL;
                ResultPtr result = NULL;
                tsv.blk->resultEnd = &result;
                tsv.matchBegin = prev->begin;
                tsv.matchEnd = prev->end;
                tsv = tSearch(tsv);
                if (result) {
                    resultPrint(prev->next,"Print");
                }
            }
// printf("%p\n",r);
        } else {
            if ((blockBegin->bitState.bitContainer & 1)!=1) r = r->next;
        }
        prev = resultPrint(r,"Print");
    }
    return 0;
}