2
$\begingroup$

I am trying to numerically solve Bloch equations using Euler's method. My code is the following

γ = 1.;  
b = {0., 0., 1.};  
θ = π/6.;  
ϕ = 0.;  
ic = {Cos[ϕ] Sin[θ], Sin[ϕ] Sin[θ], Cos[θ]};  
m0 := ic;  
m[Δt_] := m0 + Δt γ Cross[m0, b];  
run[Δt_, n_] := Table[α = m[Δt]; ic = α, {t, 1, n}];  
run1 = run[0.01, 1000];  
ListPlot[Table[Flatten[Take[run1, All, {j}]], {j, 3}], Joined -> True,  PlotRange -> All, PlotStyle -> Thick]      

enter image description here

This gives the correct result. However if I use ParallelTable instead of Table

run[Δt_, n_] := ParallelTable[α = m[Δt]; ic = α, {t, 1, n}];    

I get the following
enter image description here

What is the cause of this? ParallelTable also takes longer than Table as well. Sorry I can't get the formatting of the greek letters correctly...

$\endgroup$
9
  • 2
    $\begingroup$ Please copy and paste your code again from Mathematica and do not attempt to format the Greek letters. (They will appear as e.g. \[Phi].) $\endgroup$
    – Mr.Wizard
    Jan 21, 2015 at 22:21
  • $\begingroup$ thank you. I re-copied the mathematica code. $\endgroup$
    – user64620
    Jan 21, 2015 at 22:27
  • $\begingroup$ For such a short calculation, the overhead of parallel computations dominates any savings from using multiple processors. $\endgroup$
    – bbgodfrey
    Jan 21, 2015 at 22:35
  • $\begingroup$ Hi bbgodfrey. This is the equation of motion for only one particle. Eventually I'd like to extend this to many interacting particles, which I was hoping paralleltable would be helpful. $\endgroup$
    – user64620
    Jan 21, 2015 at 22:42
  • $\begingroup$ The problem, I believe, is that each of the parallel processes is independently changing ic. Better, I believe to calculate trajectories of multiple particles in parallel than to try to compute the trajectory of one particle with multiple processors. $\endgroup$
    – bbgodfrey
    Jan 21, 2015 at 22:49

0

Your Answer

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.