Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There seems to be a problem with ParametricNDSolveValue togeteher with ParallelTable

First we create a ParametricNDSolveValue object

f = ParametricNDSolveValue[{x'[t] == -a x[t], x[0] == 1}, (x[1] - 1)^2, {t, 0, 2}, {a}]
ParametricFunction[SequenceForm["<", ">"]]

Then we make a table of derivatives, which works fine.

Table[D[f[a], a], {2}]

Now we do the same thing in a ParallelTable, which gives a huge amount of errors.

ParallelTable[D[f[a], a], {2}]
Internal`Bag::intpm: Positive machine-sized integer expected at position 3 in Internal`Bag[{{#1,#2},{#3,#4}},#5,#6].
Thread::tdlen: Objects of unequal length in {0}+{0,0,0,0,0,0,0,0,0}+<<11>>+0& (<<33>>^(<<1>>))[0,<<8>>,{1.}]+(Internal`Bag^({{0,0},{0,1}},0,0))[{{t$8850,a$8849},{t,a}},1,2] (NDSolve`NDSolveParametricFunction^(0,{0,1},<<6>>,{},{0}))[0,{ParametricNDSolveValue,Internal`Bag[<2>]},<<6>>,{},{1.}] cannot be combined.

If we use Deriviative this works fine

ParallelTable[Derivative[1][f][a], {2}]

Is this a bug in ParametricNDSolve?

share|improve this question

The problem with this case seems to be that objects with internal state have trouble being communicated to the sub kernels; It may be better to evaluate the state generating function (ParametricNDSolveValue in this case) on the sub kernels in the first place. This is not too expensive.

 f = ParametricNDSolveValue[{x'[t] == -a x[t], 
    x[0] == 1}, (x[1] - 1)^2, {t, 0, 2}, {a}]]

Then you can work with the properly set up f in the sub kernels:

ParallelTable[D[f[a], a], {2}]
share|improve this answer
Very good, didn't think of that. – jaclea Sep 11 '13 at 8:42
Do these objects with internal state have similar problems at other places, e.g. write to/read from disk, "serializing" via "Compress"/"Uncompress"? Are you thinking about addressing this in the future? There could well be cases where the evaluation of the differential equation(s) on all parallel kernels might be expensive (especially concerning memory usage) und not a practical workaround... – Albert Retey Sep 13 '13 at 10:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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