現在地 >> メニュー >> OpenMP >> OMP::HelloWorld

OMP::HelloWorld2

問題


すべてのスレッドで文字列を出力せよ。

その他条件:
 その出力が全スレッドのどこからのものなのかを出力する。

答え


#include <omp.h>
#include <cstdio>

int main()
{

#pragma omp parallel
{
printf("hello, OpenMP from %d of %d\n",
omp_get_thread_num(), omp_get_num_threads());
}

}

メモ


共有メモリマシンで実行する場合、何も指定しない場合、何個のCPUがあるかをチェックし、
それと同じ数のスレッドが生成される。


[スレッドの生成例]

  • dual core → 2スレッド
  • quad core → 4スレッド


[dual coreの出力例]

hello world from 0 of 2
hello world from 1 of 2

目次

― その他 ―

Wiki内検索

計測中...(07.10.8〜)

Save The World






▲よろしければ広告のクリックもお願いします


▲ランキングに参加しました

管理人/副管理人のみ編集できます