2
$\begingroup$

Mathematica has a useful set of Operators Without Built-In Meanings. For example: CenterDot, CircleDot, CirclePlus, Star, etc. According to the linked documentation, a user is allowed to define evaluation rules for these symbols. Unfortunately, these symbols are not compatible with parallel evaluation. The following example shows how parallel evaluation leads to an incorrect result when user-defined evaluation rule for CenterDot is used:

CenterDot = Times;
DistributeDefinitions[CenterDot];
f[n_] := Coefficient[CenterDot[n, x], x];

Table[f[n],{n,1,5}]

{1,2,3,4,5} (* correct *)

ParallelTable[f[n],{n,1,5}]

{0,0,0,0,0} (* wrong *)

I think that the root cause of this bug is that parallel evaluation routines are not allowed to distribute definitions of any symbols from System context while all Operators Without Built-In Meanings are defined in this very context.

Is there a practical way to use Operators Without Built-In Meanings in parallel calculations?

This question is based on observations made here, where accepted workaround was just to abandon such operators altogether.

$\endgroup$
  • 1
    $\begingroup$ Some comments to one of your linked questions suggest using ParallelEvaluate: (1), (2) $\endgroup$ – Michael E2 Aug 6 at 10:31
3
$\begingroup$

Is there a practical way to use Operators Without Built-In Meanings in parallel calculations?

The simpler workaround is to create the definition directly on the parallel kernels.

CenterDot = Times
ParallelEvaluate[CenterDot = Times]

This must be done every time after a new subkernel is started.


A better solution is to put the definitions in a package and load that package using ParallelNeeds. This is more robust because ParallelNeeds affects not only currently running subkernels, but also subkernels that will be started in the future. I'd recommend this second approach.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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