Visual Studio中的OpenMP任务 [英] OpenMP tasks in Visual Studio
问题描述
我试图学习基于OMP库任务的编程,作为一个例子,我复制和粘贴下面的代码从一本书,并输出错误
I am trying to learn OMP library task based programming and as an example I copied and pasted the code below taken from a book and it outputs errors
'task' : expected an OpenMP directive name
和
'taskwait' : expected an OpenMP directive name
我可以运行omp parallel for循环,但不能运行任务。你是否知道omp任务是否需要在visual studio中进一步调整?
I can run omp parallel for loops but not tasks. Do you know whether omp tasking needs any further adjustments in visual studio?
#include "stdafx.h"
#include <omp.h>
int fib(int n)
{
int i, j;
if (n<2)
return n;
else
{
#pragma omp task shared(i) firstprivate(n)
i=fib(n-1);
#pragma omp task shared(j) firstprivate(n)
j=fib(n-2);
#pragma omp taskwait
return i+j;
}
}
int main()
{
int n = 10;
omp_set_dynamic(0);
omp_set_num_threads(4);
#pragma omp parallel shared(n)
{
#pragma omp single
printf ("fib(%d) = %d\n", n, fib(n));
}
}
推荐答案
,即使Visual Studio 2013仍然只支持 OpenMP 2.0 ,而任务是 OpenMP 3.0添加和<在撰写本文时,a href =http://openmp.org/wp/openmp-specifications/>当前标准为4.0。
Unfortunately, even Visual Studio 2013 still only supports OpenMP 2.0, while Tasks were an OpenMP 3.0 addition and the current standard at the time of writing is 4.0.
这篇关于Visual Studio中的OpenMP任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!