0
$\begingroup$

My aim is to use Manipulate option on the ParametricNDSolveValue. When ever i run my code "Manipulate" option runs very slow and some time shows Aborted when check for that value of parameter it works perfectly fine. My actual equations are very big and takes a lot of time for computing. Here i'm providing a toy problem, I wanted to use parallel programming (I don't know how to perform parallel coding). and also be able to use Manipulate option. Kindly anyone provide a solution.

ClearAll[Evaluate[StringJoin[Context[], "*"]]]
Needs["Utilities`CleanSlate`"]; 
CleanSlate[]; 
ClearInOut[];   

f1[a_, t_, x1_, x2_] := a*Sin[t*x1] + 
    Cos[x2]/(1 + a);  

f2[a_, t_, x1_, x2_] := 1/(1 + a*t) + 
    a*Sin[x1];  

sol1 := ParametricNDSolveValue[
   {Derivative[1][x1][t] == 
     f1[a, t, x1[t], x2[t]] + x2[t], 
    Derivative[1][x2][t] == f2[a, t, x1[t], 
      x2[t]], x1[0] == 0.001, x2[0] == 0}, 
   {x1, x2}, {t, 0, 10}, {a}]  

Manipulate[Plot[Evaluate[(#1[t] & ) /@ 
     sol1[a]], {t, 0, 10}, PlotRange -> 
    {{0, 10}, {-20, 20}}, PlotLegends -> 
    {x1, x2}], {{a, 1}, 0, 10, 0.1}] 
$\endgroup$
  • 1
    $\begingroup$ Look up SynchronousUpdating and DynamicEvaluationTimeout, and see this tutorial. Step integration of ODEs is not possible to parallelize much because you need to compute one step before you can compute the next. If a single step needs a lot of computation (not the case in the example), parallelization might be useful, but the user has no control over this. (For instance, some integration methods use linear algebra routines, and the libraries automatically parallelize some operations for you.) $\endgroup$ – Michael E2 Dec 30 '19 at 14:58
  • 1
    $\begingroup$ One small improvement: Use sol1 = ParametricNDSolveValue instead of sol1 := ParametricNDSolveValue. The Finite Element Method (for the ODE) uses parallelized linear algebra, but it doesn't seem to give a good result on the example. $\endgroup$ – Michael E2 Dec 30 '19 at 15:14
  • $\begingroup$ @Michael Thanks a lot for the response . I wanted to solve the given differential equation for parameter a=0 and then for another case a=0.1 and so on upto a=10. Manipulate option is very slow i need to click on the next option in Manipulate. I observe that Mathematica starts to compute the instant i clicked on next in Manipulate option. My aim was to parallel list whole code for different parameter "a" values $\endgroup$ – Gummala Navneeth Dec 31 '19 at 4:47
  • $\begingroup$ Can you precompute all 101 solutions? The ParametricFunction that ParametricNDSolveValue returns will cache the last solution computed, so that you can use it repeatedly without having to reintegrate the ODE. But it does not cache all of the solutions. Use sol1[a_] := sol1[a] = NDSolveValue[..]. $\endgroup$ – Michael E2 Dec 31 '19 at 5:18

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.