is it possible to parallelize a for loop starting the max value, then decrement ? In the Parallel.For signature, it seems to be only the case when “i” increments
for (int i = Int32.MaxValue; i >= 0; --i)
{
// do something...
}
Regards,
Florian
It should not matter if you are writing parallel code:
MSFT does not guarantee that the loop will run from low to high, or in any particular order.
In practice, Parallel.For absolutely does not run in order.
Consider Jeppe Stig Nielsen’s example (from comments):
On my machine with 4 cores, I got the following output:
Clearly the loop is not in order.