score:1

Accepted answer

you're looking for parallelenumerable.asordered:

var result = sequence
    .asparallel()
    .asordered()
    .aggregate(seed: string.empty, func: (prev, current) => prev + current);

the fact that you need to preserve ordering will have a performance hit on your query. as the results need to be aggregated in order, you won't be enjoying the maximum benefit of parallelism, and may sometimes lead to degraded performance over sequential iteration. having said that, this will do what you're after.

for example, the following code will produce "[7][35][22][6][14]" consistently:

var result = new [] { 35, 14, 22, 6, 7 }
    .asparallel()
    .asordered()
    .select(c => "[" + c + "]")
    .aggregate(seed: string.empty, func: (prev, current) => prev + current);

console.writeline(result);

there is a good post about plinq ordering by the parallel programming team.


Related Query

More Query from same tag