view regexParser/cerium/ppe/Exec.cc @ 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 6cc1d9779f45
children 87a801c14117
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;
    tsv.buff = buff;
    tsv.tg = tg;
    if (task_spawned == 0) {
        tsv.current = tg->stateList->tState;
    } else {
        tsv.current = tg->anyState->tState;
    }
    tsv.result = NULL;
    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;
    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 = 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;
}

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 = buff.matchBegin = i_data;
    buff.buffend = buff.buff + length;
    TSValue tsv = blockSearch(tg,buff,task_spawned);
//    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;
    return 0;
}