c# - How to initialize large array parallel with PLINQ? -
i trying initialize simple (but large) array, using plinq:
void test(int width, int height) { var foo = new foo[width * height]; foo.asparallel().forall(c => new foo()); }
but leave me array of width x height null (uninitialized) elements.
surely must possible since operation can paralyzed(?).
what correct syntax perform initialization plinq?
i don't doubt there way initialize array linq in parallel, but, i'd suggest using parallel.for instead:
var foo = new foo[width * height]; parallel.for(0, foo.length, => foo[i] = new foo());
edit: since want proper plinq solution (also, fixed typo pointed out):
var foo = enumerable.range(0, width * height) .asparallel() .select(x => new foo()) .toarray();
Comments
Post a Comment