2
$\begingroup$

I am using NDSolve on a workstation with 6 kernels. To speed up the simulation I have used LaunchKernels[] to load all the available parallel kernels. I am not sure whether or not this simple command makes the simulation a parallel computation? However, I found that the running time with LaunchKernels[] is the nearly the same order of that without LaunchKernels[].

My questions are:

  1. What on earth does LaunchKernels[] do for a particular computation? Or under what circumstances should I use LaunchKernels[]?

  2. How do you tell Mathematica to compute parallelly on a workstation or a dual-core laptop? For example, how to parallelize this example:

    fsol = NDSolve[{D[u[x, t], t] == D[u[x, t], x, x], u[x, 0] == 1 - Sin[4*Pi*x]/(4*Pi), u[0, t] == 1, u[1, t] + Derivative[1, 0][u][1, t] == 0}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 100}}]; Plot[First[u[1, t] + Derivative[1, 0][u][1, t] /. fsol], {t, 0, 1}, PlotRange -> All]

$\endgroup$
2
  • 2
    $\begingroup$ no that is not enough: you have to explicitly tell Mathematica to (attempt to) run an evaluation in parallel, through one of the many commands available for this purpose, like Parallelize, ParallelTable and so on $\endgroup$
    – glS
    Commented Aug 8, 2016 at 9:19
  • 2
    $\begingroup$ I don't believe NDSolve[] is parallelizable. $\endgroup$ Commented Aug 8, 2016 at 12:58

1 Answer 1

2
$\begingroup$

If you use the method FiniteElement instead of TensorProductGrid the parallelization is done automatically :

fsol = NDSolveValue[{
   D[u[x, t], t] == D[u[x, t], x, x] + NeumannValue[-u[x, t], x == 1],
   u[x, 0] == 1 - Sin[4 Pi x]/(4 Pi),
   u[0, t] == 1
   },
  u,
  {x, 0, 1}, {t, 0, 3},
  MaxStepSize -> 0.0001,
  Method -> {"MethodOfLines", 
    "SpatialDiscretization" -> {"FiniteElement", 
      "MeshOptions" -> {"MaxCellMeasure" -> {"Length" -> 0.001}}}}
  ]  

Manipulate[
 Plot[fsol[x, t], {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1.1}}], {t, 0, 
  1}]

enter image description here

On Windows, The parallelization is visible on the "Windows Task Manager"

MaxStepSize-> 0.0001 and "MeshOptions" -> {"MaxCellMeasure" -> {"Length" -> 0.001}} are used here to increase the computing time.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.