A numerical library which uses a paralleled algorithm to do one dimensional integration? -
is there numerical library can use paralleled algorithm 1 dimensional integration (global adaptive method)? infrastructure of code decides cannot multiple numerical integrations in parallel, have use paralleled algorithm speed up.
thanks!
nag c numerical library have parallel version of adaptive quadrature (link here). trick request user following function
void (*f)(const double x[], integer nx, double fv[], integer *iflag, nag_comm *comm)
here function "f" evaluates integrand @ nx
abscise points given vector x[]
. parallelization comes along, because can use parallel_for
(implemented in openmp example) evaluate f
@ points concurrently. integrator single threaded.
nag expensive library, if code integrator using, example, numerical recipes, not difficult modify serial implementations create parallel adaptive integrators using nag idea.
i can't reproduce numerical recipes book show modifications necessary due license restriction. let's take simplest example of trapezoidal rule, implementation quite simple , known. simplest way create adaptive method using trapezoidal rule calculate integral @ grid of points, double number of abscise points , compare results. if result changes less requested accuracy, there convergence.
at each step, trapezoidal rule can computed using following generic implementation
double trapezoidal( void (*f)(double x), double a, double b, int n) { double h = (b - a)/n; double s = 0.5 * h * (f(a) + f(b)); for( int = 1; < n; ++i ) s += h * f(a + i*h); return s; }
now can make following changes implement nag idea
double trapezoidal( void (*f)( double x[], int nx, double fv[] ), double a, double b, int n) { double h = (b - a)/n; double x[n+1]; double fv[n+1]; for( int = 0; < n; ++i ) x[i+1] = (a + * h); x[n] = b; f(x, n, fv); // inside f, use parallel_for evaluate integrand @ x[i], i=0..n double s = 0.5 * h * ( fv[0] + fv[n] ); for( int = 1; < n; ++i ) s += h * fv[i]; return s; }
this procedure, however, speed-up code if integrand expensive compute. otherwise, should parallelize code @ higher loops , not inside integrator.
Comments
Post a Comment