I'm finding that precision of variables updated outside ParallelTable don't update inside of it the way I'd hope. Here's the minimal code that demonstrates my point:
a1 = SetPrecision[1.0, 20];
Precision[a1]
ParallelTable[
Print[Precision[a1]];
, {j, 1}];
a1 = SetPrecision[1.0, 30];
a2 = a1;
Precision /@ {a1, a2}
ParallelTable[
Print[Precision /@ {a1, a2}];
, {j, 1}];
which outputs
20.
20.
{30., 30.}
{20.,30.}
The key problem is that output lines 3 and 4 aren't the same. a1 is defined differently inside and outside ParallelTable. Why is this and how can I make sure a1 is properly updated?
For contrast, note the problem does not occur if a1 has its value updated instead of its precision:
a1 = 1.0;
a1
ParallelTable[
Print[a1];
, {j, 1}];
a1 = 2.0;
a2 = a1;
{a1, a2}
ParallelTable[
Print[{a1, a2}];
, {j, 1}];
output:
1.
1.
{2., 2.}
{2.,2.}
Some possibly related questions:
-- This seems to answer a related but different question?
ParallelTable and Table do not give same result
-- I couldn't quite grasp this one to figure out if it was answering my question. A more straightforward answer would be very helpful.
SetSharedVariable[a1, a2];after the assignmenta2=a1. This will fix it. Not completely sure what's going on though... – Lukas Jun 06 '16 at 08:19ParallelEvaluateto update the precision. – sebhofer Jun 06 '16 at 11:30a2correct on the slave? That disturbed me – Lukas Jun 06 '16 at 11:38a1anda2:a1already exists in the context of the slave kernels, whilea2does not.ParallelTableautomatically distributes the definition ofa2, but apparently does not updatea1(which seems to be reasonable behaviour to me). Again, I didn't check this in detail, just a guess. – sebhofer Jun 06 '16 at 11:46a1existed before the firstParallelTable. I guess you're right – Lukas Jun 06 '16 at 11:48