1
$\begingroup$

I don't understand the strange behaviour below. Is this expected?

Clear[a];
b = a;
f[x_] = a x;
a = 1;

Block[ {a = 2}, {a, b, f[x]}]
ParallelEvaluate[ a = 2; {a, b, f[x]}] // First

Results:

{2, 2, 2 x}
{2, 2, x}

Only when executed in parallel, the value of f[x] does not depend on a. Variables, like b above, do not have this behaviour. Why?

I understand that this is related to how the functions definitions are sent to the subkernels. This seems to me to be a bug. Or am I wrong?

Another variation:

Clear[f, a]; 
f[x_] = a x; 
a = 1; 
Table[a = 2; f[x], {i, 1}]
a = 1;
ParallelTable[a = 2; f[x], {i, 1}]

Results:

{2 x}
{x}
$\endgroup$

1 Answer 1

1
$\begingroup$

I contacted Wolfram and received the answer that the issue above was sent to the developers.

It is a small issue, but I would not expect this behaviour.

One can also check that the issue is not on how f[x] is processed in the kernel, since the very definition of f[x] in the subkernels is different, as it can be checked using DownValues.

ParallelEvaluate[DownValues[f]] // First 

(*{HoldPattern[f[x_]]:>x}*)
$\endgroup$

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.