In a previous questionprevious question I asked how to speed up the performance for NDSolve for a single evaluation. With the help provided, the solution is much faster. Now, I'd like to run the same code in different cores simultaneously.
Here is the same code as before, except in a Module:
func[var_] := Module[{x = var},
Print["Starting to evaluate with x = ", x];
gamma = 176;
alphag = 0.01;
alphajConstant = 0.00603;
p = {Cos[Pi/6], 0, Sin[Pi/6]};
current[t_] := Simplify`PWToUnitStep@Piecewise[{{3, t <= x}, {(5 - 3)/(150 - x) (t - x) + 3, x < t < 150}, {5, t >= 150}}];
Beff[t_] := {0, 0, 1.5 - 0.8*(m[t].{0, 0, 1})};
cons[t_] := -gamma*Cross[m[t], Beff[t]];
tGilbdamp[t_] := alphag*Cross[m[t], cons[t]];
tSlondamp[t_] :=
current[t]*alphajConstant*gamma*Cross[m[t], Cross[m[t], p]];
equ= {m'[t] == cons[t] + tGilbdamp[t] + tSlondamp[t], m[0] == {0, 0, 1}};
sol1 = NDSolve[equ, {m}, {t, 0, 200}, MaxSteps -> \[Infinity]];
mm[t_] = m[t] /. sol1[[1]];
Print[Plot[mm[t][[1]], {t, 0, 200}]];];
And here is my attempt to run it in parallel processes:
LaunchKernels[2]
ParallelEvaluate[func[50], Kernels[][[1]]]
ParallelEvaluate[func[100], Kernels[][[2]]]
As far as I can tell, these do not run simultaneously; they run sequentially. Also, looking at the performance monitor on my Window 10 machine, the different cores don't seem to be working separately. What am I doing wrong?