0
$\begingroup$
Module[{K = 1, fn}, fn[p_] := Print[K]; 
  ParallelTable[fn[p0], {p0, 2}]];

Prints K$316 (or whatever the module counter is on), while

Module[{k = 1, fn}, fn[p_] := Print[k]; 
  ParallelTable[fn[p0], {p0, 2}]];

prints 1.

(1) I figure that K is reserved somehow, is that right? It prints black in the GUI, but isn't in the documentation anywhere that I can find. What tools do I have to investigate the object K in the global namespace?

(2) Why is this the case even in a module?

$\endgroup$
  • 1
    $\begingroup$ You are right. Type ?K and press Enter. You will get the information on K $\endgroup$ – Alexei Boulbitch Aug 16 '18 at 12:28
  • $\begingroup$ The issue here is your use of ParallelTable. It seems that the local variable K$316 created by Module is not distributed. This makes the kernels doing the computation see the global value of K. If you try again with Table, you'll see that it prints 1. $\endgroup$ – march Aug 16 '18 at 16:18

Your Answer

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

Browse other questions tagged or ask your own question.