Cerium Task Manager
による正規表現の実装

Masataka Kohagura
19th November , 2013

研究目的

マルチコア CPU を最大限に活かすためには、並列プログラミングによる並列度を向上させなければならないが、実装が難しい。 当研究室では Cerium Libraryを提供することによって並列プログラミングを容易にしているが、ファイル読み込み等のI/O部分に関してはまだ実装されていない。

本研究ではその例題として正規表現を実装し、I/Oの並列化の設計・実装によって既存の正規表現の処理速度、処理効率を上げる。

今週のしたこと

・検索文字列のハードコーディングの脱却
(set_inData,get_input絡みでバグ??)

WordCount.h

typedef struct wordCount {
    struct wordCount *self;
    int size;             // remaining file size
    int division_size;    // for each word count task
    (中略)
    unsigned char *search_word;
    int search_word_len;
    HTaskPtr t_print;
} WordCount;

main.cc(task生成部分)

run_tasks(SchedTask *manager,…)
{
    …
    if(size != w->size){ //最後のタスクかどうかの判定
        t_exec[k]->set_param(0,&set_one_task_length + EXTRA_LENGTH);
        t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size+EXTRA_LENGTH);
        t_exec[k]->set_inData(1,w->search_word, w->search_word_len); 
    }else{
        t_exec[k]->set_param(0,&set_one_task_length);
        t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size);
        t_exec[k]->set_inData(1,w->search_word, w->search_word_len); 
    }
    …
}

main.cc(task生成部分)

run_tasks(SchedTask *manager,…)
{
    …
    if(size != w->size){ //最後のタスクかどうかの判定
        t_exec[k]->set_param(0,&set_one_task_length + EXTRA_LENGTH);
        t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size+EXTRA_LENGTH);
        t_exec[k]->set_inData(1,w->search_word, w->search_word_len); 
    }else{
        t_exec[k]->set_param(0,&set_one_task_length);
        t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size);
        t_exec[k]->set_inData(1,w->search_word, w->search_word_len); 
    }
    …
}

問題点

  • 複数の文字列をタスクに渡そうとすると、最初に渡す文字列に関しては渡せるが、後に渡す文字列がうまく渡らない。
  • Exec.cc(get_input)

    run(SchedTask *s, void *rbuf, void *wbuf)
    {
        unsigned char *i_data = (unsigned char *)s->get_input(rbuf,0);
        unsigned char *search_word = (unsigned char*)s->get_input(rbuf,1);
            …
        s->printf("[i_data]\n%s\n",i_data);
        s->printf("[search_word]\n%s\n",search_word);
    
        return 0;
    }
    

    result

    (lldb) p i_data
    (unsigned char *) $2 = 0x000000010202ca00 "aaa bbb …"
    (lldb) p search_word
    (unsigned char *) $3 = 0x000000010202ca00 "aaa bbb …"
    
  • 文字列を複数受け取ろうとすると、index(1)のアドレスがindex(0)のアドレスと同じ場所を示す
  • この時のi_data sizeは8byte、search_word sizeは6Byteである。
  • i_data size = search_word sizeにしても同様