# ParallelTable giving totally wrong answer

Following suggestion I created the simplest error giving code

Star[f_, g_] := Sum[  D[f , {x, n}] D[g , {x, 2 - n}], {n, 1, 2}]
T1 = x + t12 x^2 + x^3; T2 = t21 x + t22 x^2 + x^4;
DistributeDefinitions[T1, T2, Star];
Star[T1, T2] // Coefficient[#, x^2] &
ParallelTable[Star[T1, T2] // Coefficient[#, x^u] & , {u, 2, 2}]
ParallelTable[Star[T1, T2], {u, 5, 5}] //Coefficient[#, x^2] &


The results of calculation are

9 t21 + 6 t12 t22
{0}
{9 t21 + 6 t12 t22}


What can be causing the problem please?

• Are StrO[u] and PrdW[u] defined in the same way in the local and remote Kernels? See DistributeDefinitions and strategies for clean kernel. Aug 2 '19 at 9:51
• BTW, Welcome to Mma.SE. Please do follow this advice: Start by taking the tour now and learning about asking and what's on-topic. Aug 2 '19 at 9:55
• @rhermans they are both defined in the same way through an ordinary ":=" the result of the calculation for ParallelTabe does shows that both definitions were used (there does not appear Str0[1] or alike Aug 2 '19 at 10:02
• Did you read the info in the links I provided? Clearly there is something different in the local evaluation that in the parallel one. Parallel kernels can have different definitions than your local kernel, solo you need to be sure that there are no lingering definitions or lack of definitions in either side. Please do follow the links and advice I provided: take the tour, check with fresh or cleaned kernel, have control over the distribution of definitions. Then report back by editing your question to add more detailed information. Do not make us guess. Aug 2 '19 at 10:07
• Personally, I feel the silent failure of DistributeDefinitions is essentially a bug. I don't mean that it should necessarily succeed, although I don't quite see why DistributeDefinitions should not be applied to un-Protected symbols when explicitly asked. What I mean is that there ought to be at least two warnings: The documentation for DistributeDefinitions should indicate the limitation with regard to "System" and other(?) contexts. DistributeDefinitions should give an error message for any arguments whose definitions will not be distributed. Aug 5 '19 at 10:25

star[f_, g_] := Sum[D[f, {x, n}] D[g, {x, 2 - n}], {n, 1, 2}]
T1 = x + t12 x^2 + x^3; T2 = t21 x + t22 x^2 + x^4;
DistributeDefinitions[T1, T2, star];
star[T1, T2] // Coefficient[#, x^2] &
ParallelTable[star[T1, T2] // Coefficient[#, x^2] &, {u, 2, 2}]
ParallelTable[star[T1, T2], {u, 2, 2}] // Coefficient[#, x^2] &


works as expected:

   9 t21 + 6 t12 t22

{9 t21 + 6 t12 t22}

{9 t21 + 6 t12 t22}


So there is something strange with the built-in SystemStar when used in parallel subkernels.

• Quite so: DistributeDefinitions[Star]; DistributeDefinitions[star] and the compare ParallelEvaluate[DownValues@Star] (no defs.) with ParallelEvaluate[DownValues@star] (defs. present). -- I think it's connected to \$DistributedContexts Aug 4 '19 at 21:16
• It's not strange, it's just that DistributeDefinitions doesn't distribute all contexts, and particularly avoids distributing the System context. Doing so could wreak havoc ... But Star happens to be one of those few System symbols for which distributing definitions actually does make sense Aug 4 '19 at 21:21
• @Szabolcs to my understanding it is definitely a bag. Star is undefined(!) system symbol. Its definition does get distributed, as you can calculate it in ParallelTable, but for some reason you cannot calculate a function of it inside the same parallel evaluation. Aug 5 '19 at 7:14
• @IgnatFialkovskiy It does not get distributed, as shown by ParallelEvaluate[Print@Definition[Star]]. This is not a bug. It's an intentional feature that prevents distributing anything within the System context. I'm sure you can see why doing that generally makes sense. You found the one very special situation where it does in fact make sense to distribute the definition of a System symbol, but such cases are unusual and rare. Aug 5 '19 at 7:19
• @IgnatFialkovskiy The Star expression will evaluate as soon as it gets returned from the subkernels. The evaluation happens on the main kernel, after the Star[...] has been returned, not on the subkernels. Aug 5 '19 at 9:22