Is there a mechanism for using plinq on platform 3.5? As it came across using the usual linq on 2.0 using the linq bridge. Find something similar for plinq could not. Any ideas?
1 answer
Open with the reflector the code of the extending method for parallelization and copy.
At one time we used this:
private void ParallelFor(int from, int to, Action<int> body) { int numProcs = Environment.ProcessorCount * 2 + 4; // количество оставшихся int remainingWorkItems = numProcs; int nextIteration = from - 1; ThreadPool.SetMaxThreads(numProcs, numProcs); using (ManualResetEvent mre = new ManualResetEvent(false)) { for (int p = 0; p < numProcs; p++) { ThreadPool.QueueUserWorkItem(delegate { int index = 0; while ((index = Interlocked.Increment(ref nextIteration)) < to) body(index); if (Interlocked.Decrement(ref remainingWorkItems) == 0) mre.Set(); }); } // ждём, пока отработают все задания mre.WaitOne(); } } - Thanks, good idea. I'm actually interested in the basic AsParallel method. Do you think it can be obtained in this way? - Pavel S. Zaitsau
- oneI think yes. - Modus
|