如何在 Mathematica 8 中并行集成
有人知道如何使用所有核心来计算积分吗?我需要使用并行化或并行表,但如何使用?
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将列表的集成更改为集成列表,以便可以使用
ParallelTable
:在我的时间安排中,使用
{j, 5, 30, 1}
而不是 < code>{j, 5, 200, 1} 来限制使用的时间,这在我的 quod-core 上大约快了 3.4 倍。但它可以更快地完成:这大约快了 6.8 倍,其中 2.3 倍是由于
Parallelize
。当涉及并行执行时,
Timing
和AbsoluteTiming
不太值得信赖。我在每行之前和之后使用了AbsoluteTime
并获取了差异。编辑
我们不应该忘记 ParallelMap:
在最粗的列表级别 (1):
在最深的列表级别(最细粒度的并行化):
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):
如果首先通过扩展矩阵元素来帮助积分,
只要付出一点努力,事情就可以完成。
在装有 Windows 和 Mathematica 8.0.4 的四核笔记本电脑上,运行以下代码
对于要求的 DIM=200 在大约 13 分钟内,
对于 DIM=50,代码运行时间为 6 秒。
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.