# ParallelTable of ParametricNDSolve objects fail

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}]
InternalBag::intpm: Positive machine-sized integer expected at position 3 in InternalBag[{{#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.}]+(InternalBag^({{0,0},{0,1}},0,0))[{{t$8850,a$8849},{t,a}},1,2] (NDSolveNDSolveParametricFunction^(0,{0,1},<<6>>,{},{0}))[0,{ParametricNDSolveValue,InternalBag[<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?

-

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.

ParallelEvaluate[
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}]
`
-
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