PLINQ at 3.5.net Framework



  • Is there a plinq facility on platform 3.5? Somehow, using conventional linq by 2.0 using linq bridge. I couldn't find anything like this for plinq. Any ideas?



  • Open the reflexor code of the expanding method for diluting and copy.

    In our 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();
    

    }
    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2