我正在尝试使用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);
}