Ceriumによる
正規表現マッチャの実装

Masataka Kohagura
7th May , 2013

研究目的

本研究室では、Cell用に作られたCeriumにて並列プログラミングを行なっている。 近年、マルチコアCPUが主流となっているが、それをフルに使用させるためにはプログラムの並列度を上げる必要がある。(続く)

現在は正規表現を並列実装している段階である。

今週までにしたこと

C言語ポインタ完全制覇でポインタの勉強(半分ほど)

Exec.cc


    for (; i < length; i++) {
        if (i_data[i] == 0x0A) {
    
            if (match_flag == true) {
                line_print(line_num,line_length,line_data);
            }   
            match_flag = false;
            line_length = 0;
            line_num++;
        } else {
            line_data[line_length] = i_data[i];
            line_length++;
              if (i_data[i] == 0x61) {
                  a_flag = true;
              }else if ((i_data[i] == 0x62) && (a_flag == true)) {
                  match_flag = true;
              }else if (i_data[i] == 0x20) {
                  a_flag = false;
              }   
        }   
    } 

line_print(line_num,line_length,line_data);

void line_print(int _line_num,int _line_length,char *input_data){

    printf("%d : ",_line_num);
    for (int k = 0; k < _line_length; k++) {
        printf("%c",input_data[k]);
    }   
    printf("\n");
}

実行結果(分割されないような小さなファイル)

[Masa]~%  ./regex -file b.txt                   [~/hg/Cerium/example/regex_mas]
1 : ab aaa dddd ssss abab
2 : ab bbbbbbbbbb aaaaaaa
4 : ab aaaab 
        

実行結果(分割されるようなファイル)

[Masa]~%  ./regex -file c.txt                   [~/hg/Cerium/example/regex_mas]
1 : Pakistan who've volunteered to join private militias, called lashkars. These groups have vowed to help Pakistan's military in fighting the Taliban.
5 : Pakistani military officials credit the lashkars with helping chase the Taliban out of Swat Valley and neighboring districts once infested with the militants.
6 : Pakistan who've volunteered to join private militias, called lashkars. These groups have vowed to help Pakistan's military in fighting the Taliban.
[中略]
196 : Pakistan who've volunteered to join private militias, called lashkars. These groups have vowed to help Pakistan's military in fighting the Taliban.
200 : Pakistani military officials credit the lashkars with helping chase the Taliban out of Swat Valley and neighboring districts once infested with the militants.
1 : red to join private militias, called lashkars. These groups have vowed to help Pakistan's military in fighting the Taliban.
5 : Pakistani military officials credit the lashkars with helping chase the Taliban out of Swat Valley and neighboring districts once infested with the militants.