title: is it possible to get an average of a set of numbers that is split across processes?
body: <p>Got a good answer on math SE: <a href="https://math.stackexchange.com/questions/864657/can-i-get-the-correct-average-of-a-set-of-numbers-from-the-averages-of-several-s">https://math.stackexchange.com/questions/864657/can-i-get-the-correct-average-of-a-set-of-numbers-from-the-averages-of-several-s</a></p>
  
  <p>Let's say I have a stream of numbers: </p>
  
  <pre><code>565
  212
  812
  895
  443
  73
  468
  900
  299
  993
  252
  740
  291
  112
  (and thousands more)
  </code></pre>
  
  <p>Each message that I'm getting in contains the number and a few other things that need to be processed. Some of the processing may be time consuming so I'd like to split it into multiple processes. I'd like to send the numbers out to one of <code>n</code> processes in a roundrobin (or ZMQ router/dealer) style and do some processing on the numbers. The problem is that I'd like to keep a rolling average of all the numbers <strong>across separate processes</strong>: </p>
  
  <p><code>INPUT -&gt; Worker #n -&gt; Average collector -&gt; OUTPUT</code></p>
  
  <p>If I split the numbers up into a group of three and take the average of the subset, then an average of the three averages, I get an incorrect result. Is it possible to split this work across multiple processes? The alternative would be to push just the numbers out to an <code>Averager</code> process. That seems fine but I wonder if there's a simpler solution that I'm missing. </p>