I am using Mathematica 11.3 and this seems to me to be a bug. I would like, if possible, some idea on a workaround.
Here is an example of a trivial code that works as expected:
nI = 10; (NM[#] := Print[#] ) & /@ Range[1, nI]; LaunchKernels; DistributeDefinitions[NM];
That is, the code above generates no output, as expected.
Now, if the first line is changed to
nI = 20;
The same code leads to 40 lines being printed! From 1 to 20 two times.
For some reason, the DistributeDefinitions is forcing the definition of NM to be executed, and I do not want that to happen before I use ParallelSubmit and WaitAll. I tried this in two computers with Mathematica 11.3, any ideas on what is happening?