view regexParser/cerium/ppe/Exec.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 63213964502a
children cc770cd8d000
line wrap: on
line source

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

/* これは必須 */
SchedDefineTask1(Exec,blockedGrep);

TSValue blockSearch(TransitionGeneratorPtr tg,Buffer buff,int task_spawned) {
    TSValue tsv = createTSValue(tg,buff);
    BlockOutput blk;
    tsv.blk = &blk;
    tsv.current = tg->stateStart->tState;
    tsv.blk->result = NULL;
    ResultPtr result = NULL;
    tsv.blk->resultEnd = &result;
    unsigned char *end = tsv.buff.buffend;
    tsv.buff.buffend = end;
    tsv = tSearch(tsv);
    tsv.blk->blockEnd = tsv.current;
    addResult(tsv,true,buff.buff,buff.buffend);  // entire buffer
    if (tsv.blk->blockEnd->state->bitState.bitContainer != 1) {
        if (tsv.matchBegin != tsv.buff.buffptr) {
            // partial match case at block end.
            addResult(tsv,true,tsv.matchBegin,tsv.matchEnd);
// printf("Exec %lx r->begin : %p r->end : %p\n",tsv.blockEnd->state->bitState.bitContainer, r->begin,r->end);
        }
    }
    tsv.blk->result = result;
    return tsv;
}

static int
blockedGrep(SchedTask *s, void *rbuf, void *wbuf)
{
    long task_spawned = (long)s->get_param(0);
    long division_size = (long)s->get_param(1);
    long length = (long)s->get_param(2);
    long out_size = (long)s->get_param(3);
    MapReduce *w = (MapReduce*)s->get_param(4);
    long allocation = task_spawned + (long)s->x;
    unsigned char* i_data;
    unsigned long * o_data;
    if (division_size) {
        i_data = (unsigned char*)s->get_input(rbuf,0) + allocation*division_size;
        o_data = (unsigned long *)s->get_output(wbuf,1) + allocation*out_size;
    } else {
        i_data = (unsigned char*)s->get_input(0);
        o_data = (unsigned long *)s->get_output(0);
    }
    TransitionGeneratorPtr tg = (TransitionGeneratorPtr)w->global;
    Buffer buff;
    buff.buff = buff.buffptr = i_data;
    buff.buffend = buff.buff + length;
    TSValue tsv = blockSearch(tg,buff,task_spawned);
//    resultPrint(tsv.result,"Exec");
    o_data[0] = (unsigned long)tsv.blk->result;
    o_data[1] = (unsigned long)tsv.blk->blockBegin->state;
    o_data[2] = (unsigned long)tsv.blk->blockEnd->state;
    return 0;
}

/* end */