Somebody have idea how to use all cores for calculating integration? I need to use parallelize or parallel table but how?
f[r_] := Sum[(((-1)^n*(2*r - 2*n - 7)!!)/(2^n*n!*(r - 2*n - 1)!))*
x^(r - 2*n - 1), {n, 0, r/2}];
Nw := Transpose[Table[f[j], {i, 1}, {j, 5, 200, 1}]];
X1 = Integrate[Nw . Transpose[Nw], {x, -1, 1}];
Y1 = Integrate[D[Nw, {x, 2}] . Transpose[D[Nw, {x, 2}]], {x, -1, 1}];
X1//MatrixForm
Y1//MatrixForm
I changed the integration of a list into a list of integrations so that I can use
ParallelTable
:In my timings, with
{j, 5, 30, 1}
instead of{j, 5, 200, 1}
to restrict the time used somewhat, this is about 3.4 times faster on my quod-core. But it can be done even faster with:This is about 6.8 times faster, a factor of 2.3 of which is due to
Parallelize
.Timing
andAbsoluteTiming
are not very trustworthy when parallel execution is concerned. I usedAbsoluteTime
before and after each line and took the difference.EDIT
We shouldn't forget ParallelMap:
At the coarsest list level (1):
At the deepest list level (most fine-grained parallelization):
If one helps Integrate a bit by expanding the matrix elements first, things are doable with a little bit of effort.
On a quad-core laptop with Windows and Mathematica 8.0.4 the following code below runs for the asked DIM=200 in about 13 minutes, for DIM=50 the code runs in 6 second.