title: How to get variable/function definitions set in Parallel (e.g. with ParallelMap)?
body: <p>I have a function that I use to look up a value based on an index.  The value takes some time to calculate, so I want to do it with <code>ParallelMap</code>, and references another similar such function that returns a list of expressions, also based on an index.  </p>
  
  <p>However, when I set it all up in a seemingly reasonable fashion, I see some very bizarre behaviour.  First, I see that the function appears to work, albeit very slowly.  For large indexes, however, the processor activity in Taskmangler stays entirely at zero for an extended period of time (i.e. 2-4 minutes) where all instances of Mathematica are seemingly inert. Then, without the slightest blip of CPU use, a result appears.  Is this another case of Mathematica <a href="http://en.wikipedia.org/wiki/Spooky_action_at_a_distance" rel="nofollow">spukhafte Fernwirkung</a>?</p>
  
  <p>That is, I want to create a variable/function that stores an expression, here a list of integers (<code>ListOfInts</code>), and then on the parallel workers I want to perform some function on that expression (here I apply a set of replacement rules and take the <code>Min</code>).  I want the result of that function to also be indexed by the same index under another variable/function (<code>IndexedFunk</code>), whose result is then available back on the main instance of Mathematica:</p>
  
  <pre><code>(*some arbitrary rules that will convert some of the integers to negative values:*)
  rulez=Dispatch[Thread[Rule[Range[222],-Range[222]]]];
  
  maxIndex = 333;
  Clear[ListOfInts]
  Scan[(ListOfInts[#]=RandomInteger[{1,999},55])&amp;,Range[maxIndex ]]
  (*just for safety's sake:*)
  DistributeDefinitions[rulez, ListOfInts]
  
  Clear[IndexedFunk]
  (*I believe I have to have at least one value of IndexedFunk defined before I Share the definition to the workers:*)
  IndexedFunk[1]=Min[ListOfInts[1]]/.rulez
  (*... and this should let me retrieve the values back on the primary instance of MMA:*)
  SetSharedFunction[IndexedFunk]
  
  (*Now, here is the mysterious part: this just sits there on my multiprocessor machine for many minutes until suddenly a result appears.  If I up maxIndex to say 99999 (and of course re-execute the above code again) then the effect can more clearly be seen.*)
  AbsoluteTiming[Short[ParallelMap[(IndexedFunk[#]=Min[ListOfInts[#]/.rulez])&amp;, Range[maxIndex]]]]
  </code></pre>
  
  <p>I believe this is some bug, but then I am still trying to figure out Mathematica Parallel, so I can't be too confident in this conclusion.  Despite its being depressingly slow, it is nonetheless impressive in its ability to perform calculations without actually requiring a CPU to do so.</p>
  
  <p>I thought perhaps it was due to whatever communications protocol is being used between the master and slave processes, perhaps it is so slow that it just appears that the processors are doing nothing when if fact they are just waiting to send the next bit of some definition or other.  In which case I thought <code>ParallelMap[..., Method-&gt;"CoarsestGrained"]</code> would be of some use.  But no, that doesn't work neither.</p>
  
  <p>A question: "Am I doing something obviously wrong, or is this a bug?"</p>