假設我有一個包含n個元素和n_threads的向量。 我想使用#pragma omp parallel
,使得每個線程接收n/n_threads塊大小, 和最後一個取決於大小寫。OpenMP基於運行時參數設置固定塊大小
#include <stdio.h>
#include <omp.h>
int main()
{
int *v = malloc (n * sizeof(int));
#pragma omp parallel for (what should i put here?)
for(i = 0; i < n; ++i)
{
++v[i];
}
return 0;
}
例:N = 10003,n_threads = 4
- thread_0應該得到2500塊
- thread_1應該得到2500塊
- thread_2應該得到2500塊
- thread_3應該得到2503大塊
我只知道運行時的矢量大小(隱含地也是chunk_size)。我試圖避免使用pthreads,但似乎我不能使用openmp來做我現在需要的東西。 –
下面是GNU OpenMP運行時間如何在Mac OS X的4個線程之間使用'schedule(static)'調度103次迭代的示例:線程0-26迭代,線程1-26迭代,線程2-26迭代,線程3 - 25次迭代。所有迭代都是連續的。 –