Mathematica Asked by user16308 on August 7, 2021
I am solving a differential equation of two closed functions using ParallelTable.
For the attached code, I thought the computation time should be approximately proportional to ltau
, because the k
is iterated once. However, the time is roughly proportional
to square of ltau
. I think that Total[s[[1;;i,i]]]
in the reassignment of r
drags computation, and should use Unevaluated
for Total[s[[1;;i,i]]]
to reduce time, but it doesn’t reduce time. I assume the parallelization should reduce the computation time for two iterations in i
and j
.
However, the parallelization decreases speed. Why? Is there any better way to improve the parallelization?
ClearAll["Global`*"];
S = {};
RR = {};
lz = 10.;
ltau = 1000.;
AbsoluteTiming[
r = ParallelTable[1., {i, lz}];
s = ParallelTable[0., {i, lz}, {j, lz}];
Do[AppendTo[RR, r];
AppendTo[S, s];
If[k == ltau, Break,
s2 = ParallelTable[s[[i,j]]+ (r[[i]]*Total[s[[1;;i,j]]]+r[[j]]*Total[s[[i,1;;j]]])
+If[i >j, r[[i]]*(1 + r[[j]])/2, r[[j]]*(1 + r[[i]])/2], {i, lz}, {j, lz}];
r = ParallelTable[r[[i]] - Total[s[[1 ;; i, i]]], {i, lz}];
];
s=s2;,{k,1,ltau}];
]
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP