I'm getting starting with OpenCL, I could see the add vector example and understand it. But I was thinking about the trapezium method. This is the code ( C ) for the integral calculation for x^2 in [a,b].
double f(double x)
{
return x*x;
}
double Simple_Trap(double a, double b)
{
double fA, fB;
fA = f(a);
fB = f(b);
return ((fA + fB) * (b-a)) / 2;
}
double Comp_Trap( double a, double b)
{
double Suma = 0;
double i = 0;
i = a + INC;
Suma += Simple_Trap(a,i);
while(i < b)
{
i+=INC;
Suma += Simple_Trap(i,i + INC);
}
return Suma;
}
The question is ¿how to obtain a kernel for integral calculation using the trapezium method?
So, I was thinking about the idea: partials[i] = integrate(a,a+offset), and then make a kernel to compute the sum of partials as mentioned Patrick87.
But, this is the best way?
Parallel processing involves taking a large task, dividing it into several smaller tasks, and then working on each of those smaller tasks simultaneously. The goal of this divide-and-conquer approach is to complete the larger task in less time than it would have taken to do it in one large chunk.
Parallel integration with spmd For parallel integration, we start with the Single Program Multiple Data, or spmd, paradigm. The Single Program refers to the fact that the same program is run on all processors concurrently while Multiple Data points to the fact that different data may be used on different processors.
The trapezoid method is just a slight refinement of doing Riemann sums. To do this in parallel, you'll want to break the interval into as many subintervals as you want there to be threads; then, have each thread integrate the function over its subinterval. Finally, do a global sum reduction over all the integrals computed in the previous phase. You can experiment with how many threads to use for each stage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With