ループカウントとループ分配

ループカウント

loop count プラグマは、ループカウントが整数定数であることを示します。このプラグマの構文は次のとおりです。

構文

#pragma loop count (n)

n は整数です。

ループカウントの値はソフトウェアのパイプライン化およびデータ・プリフェッチに使用される手法に影響を与えます。

loop count の使用例

void loop_count(int a[], int b[])

{

  #pragma loop count (10000)

  for (int i=0; i<1000; i++)

// This should enable

// software pipelinging for this loop.

    a[i] = b[i] + 1.2;

}

ループ分配

distribute point プラグマは、ループ分配実行の優先度を示します。このプラグマの構文は次のとおりです。

構文

#pragma distribute point

ループ分配は、大きなループを小さなループに分配することがあります。この手法は、より多くのループにおいてソフトウェアのパイプライン化を有効にします。

distribute point の使用例

void dist1(int a[], int b[], int c[], int d[])

{

  #pragma distribute point

// Compiler will automatically decide where to

// distribute.Data dependency is observed.

  for (int i=1; i<1000; i++) {

    b[i] = a[i] + 1;

    c[i] = a[i] + b[i];

    d[i] = c[i] + 1;

  }

}

 

void dist2(int a[], int b[], int c[], int d[])

{

  for (int i=1; i<1000; i++) {

    b[i] = a[i] + 1;

    #pragma distribute point

// Distribution will start here,

// ignoring all loop-carried dependency.

    c[i] = a[i] + b[i];

    d[i] = c[i] + 1;

  }

}