Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numerical Integration - How to parallelize it?

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?

like image 260
facundo.hpc Avatar asked Jan 08 '12 21:01

facundo.hpc


People also ask

How do you parallelize work?

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.

What is parallel integration?

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.


1 Answers

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.

like image 133
Patrick87 Avatar answered Sep 29 '22 18:09

Patrick87