配列の和プログラムをSC2に移植したら答えを間違える

表題の件でちょっと悩んだので共有します。

配列の和を分割統治法っぽく以下のように書いていると、SC1は8192 threadsで2べきのスレッド数ですが、SC2は15872 threadsで2べきじゃないので、答えが合わないので注意。

const int tid = get_tid();
const int pid = get_pid();
const int off = tid + pid * get_maxtid();
const int inc = get_maxtid() * get_maxpid();

for(int i = inc / 2; i > 0; i >>= 1) {
    if (off < i) {
        shared[off] += shared[off + i];
    }
    barrier();
}

if (off == 0) {
    y = shared[0];
}
カテゴリー: Tips

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です