1
$\begingroup$

I want to compute the multi-dimensional integral by using NIntegral with the compiled function.

I have compiled an integrand function.

It made the computation time of the integrand about 100 times faster. However, the improvement in integration time using NIntegrate was marginal.

What could be the cause of this?

The following is the sample code:

original[x_, y_, z_] := Evaluate[Sum[Sin[a x^3 + b y^2 + c z^1]/(a! b! c!), {a, 0, 20}, {b, 0, 20}, {c, 0, 20}]]

coriginal = Compile[{{x, _Real}, {y, _Real}, {z, _Real}}, Evaluate[Sum[Sin[a x^3 + b y^2 + c z^1]/(a! b! c!), {a, 0, 20}, {b, 0, 20}, {c, 0, 20}]], Parallelization -> True, CompilationTarget -> "C", RuntimeOptions -> {"EvaluateSymbolically" -> False}];

Then, the computational times for the integrand are:

AbsoluteTiming[Do[original[0.1, 0.5, 0.25], {i, 1, 100}]]
AbsoluteTiming[Do[coriginal[0.1, 0.5, 0.25], {i, 1, 100}]]

It results in:

{2.13621, Null}
{0.014804, Null}

So, next I compute their three-dimensional integral:

AbsoluteTiming[Do[NIntegrate[original[x, y, z], {x, 0, 1}, {y, 0, 1}, {z, 0, 1},  Method -> {"GaussKronrodRule", "SymbolicProcessing" -> 0}], {i, 5}]]
AbsoluteTiming[Do[NIntegrate[coriginal[x, y, z], {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, Method -> {"GaussKronrodRule", "SymbolicProcessing" -> 0}], {i, 5}]]

It results in:

{15.988, Null}
{7.97754, Null}

Why is the integration not so improved compared to the integrand?

New contributor
shohei is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
1
  • 2
    $\begingroup$ Because the execution time in NIntegrate appears not to be dominated by the time it takes to evaluate the integrando? $\endgroup$
    – MarcoB
    Aug 6 at 16:28

0

Your Answer

shohei is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.