2
$\begingroup$

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?

$\endgroup$
8
  • 1
    $\begingroup$ Are StrO[u] and PrdW[u] defined in the same way in the local and remote Kernels? See DistributeDefinitions and strategies for clean kernel. $\endgroup$
    – rhermans
    Commented Aug 2, 2019 at 9:51
  • 1
    $\begingroup$ 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. $\endgroup$
    – rhermans
    Commented Aug 2, 2019 at 9:55
  • $\begingroup$ @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 $\endgroup$ Commented Aug 2, 2019 at 10:02
  • 1
    $\begingroup$ 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. $\endgroup$
    – rhermans
    Commented Aug 2, 2019 at 10:07
  • 3
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Aug 5, 2019 at 10:25

1 Answer 1

1
$\begingroup$
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 System`Star when used in parallel subkernels.

$\endgroup$
7
  • $\begingroup$ 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 $\endgroup$
    – Michael E2
    Commented Aug 4, 2019 at 21:16
  • $\begingroup$ 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 $\endgroup$
    – Szabolcs
    Commented Aug 4, 2019 at 21:21
  • $\begingroup$ @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. $\endgroup$ Commented Aug 5, 2019 at 7:14
  • $\begingroup$ @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. $\endgroup$
    – Szabolcs
    Commented Aug 5, 2019 at 7:19
  • 1
    $\begingroup$ @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. $\endgroup$
    – Szabolcs
    Commented Aug 5, 2019 at 9:22

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.