Spark: Accumulators does not work properly when I use it in Range
<p>I don't understand why my accumulator hasn't been updated properly by Spark.</p>

<pre><code>object AccumulatorsExample extends App {
  val acc = sc.accumulator(0L, "acc")
  sc range(0, 20000, step = 25) map { _ =&gt; acc += 1 } count()
  assert(acc.value == 800) // not equals
}
</code></pre>

<p>My Spark config:</p>

<pre><code>setMaster("local[*]") // should use 8 cpu cores
</code></pre>

<p>I'm not sure if Spark distribute computations of accumulator on every core and maybe that's the problem. </p>

<p>My question is how can I aggregate all <code>acc</code> values in one single sum and get the right accumulator value (800)?</p>

<p><em>PS</em></p>

<p>If I restrict core number <code>setMaster("local[1]")</code> than all works fine.</p>