Finally in my second PLINQ assault I found an answer. And it's pretty clear.
Problem is that enumerator is not simple. It's a special multithreading
one. So how it works? Answer is that enumerator
doesn't return a next value of source, it returns a whole sum of next partition. So this code is only executed 2,4,6,8... times (based on Environment.ProcessorCount
), when actual summation work is performed inside enumerator.MoveNext
in enumerator.OpenQuery
method.
So TPL obviosly partition the source enumerable, then sum independently each partition and then pefrorm this summation, see IntSumAggregationOperatorEnumerator<TKey>
. No magic here, just could plunge deeper.