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?