OpenMP for语句中的终止测试格式不正确

时间:2019-01-07 15:30:23

标签: c++ visual-studio openmp

我正在尝试使用openMP用梯形法则计算定积分的值。我应该如何设置减少量的方法?

float trapezoidalOMP(float a, float b, float n)
{
    float dx = (b - a) / (float)(n - 1);
    int Thr = 4;
    float sum = (y(a) + y(b)) / 2.;
    #pragma omp parallel for reduction(+:sum) num_threads(Thr) 
        for (int i = 1; i < n - 1; i++)
        {
            float x = a + dx * (float)i;
            float f = y(x);
            sum += f;
        }
        return sum *= dx;
}
float y(float x)
{
    return sqrt(pow(x,2)+1);
}

0 个答案:

没有答案