我在VS2008下面的代碼:OpenMP的for循環忽略num_threads子句
int i,j;
bool pr = false;
#pragma omp parallel for private(pr) num_threads(2)
for(i=0;i<PIC_X;i++)
{
int rank = omp_get_thread_num();
int count = omp_get_num_threads();
if (!pr)
{
printf_s("Hello from thread %d of %d\n", rank, count);
pr = true;
}
for(j=0;j<PIC_Y;j++)
{
// do stuff
}
}
(不試圖使一個嵌套的OpenMP循環中,如果你想知道)。問題是,num_threads子句沒有任何效果:我只輸出了「來自線程0的Hello」。我也嘗試使用omp_set_num_threads(2)
,無濟於事。是什麼賦予了?
退房http://software.intel.com/en-us/articles/32-openmp-traps-for-c-developers/ - 它真的幫助我 – 2011-02-04 17:29:55