Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the cores to use in Parallelism

I have a feeling the answer to this is no, but using .Net 4.0's Parallelism, can you set the amount of cores on which to run i.e. if your running a Quad Core, can you set your Application to only use 2 of them?

Thanks

like image 983
Ben Avatar asked Jun 02 '10 10:06

Ben


People also ask

How do you set the maximum degree of parallelism?

To configure the max degree of parallelism optionIn Object Explorer, right-click the desired instance and select Properties. Select the Advanced node. In the Max Degree of Parallelism box, select the maximum number of processors to use in parallel plan execution.

How do I use more cores in R?

If you are on a single host, a very effective way to make use of these extra cores is to use several R instances at the same time. The operating system will indeed always assign a different core to each new R instance. In Linux, just open several the terminal windows. Then within each terminal, type R to open R.

What is degree of parallelism in SQL Server?

SQL Server Degree of Parallelism is the processor conveyance parameter for a SQL Server operation, and it chooses the maximum number of execution distribution with the parallel use of different logical CPUs for the SQL Server request.


1 Answers

Yes, it is a built-in capability of Parallel.For(). Use one of the overloads that accepts a ParallelOptions object, set its MaxDegreeOfParallelism property. For example:

using System;
using System.Threading.Tasks;

class Program {
  static void Main(string[] args) {
    var options = new ParallelOptions();
    options.MaxDegreeOfParallelism = 2;
    Parallel.For(0, 100, options, (ix) => {
      //..
    });
  }
}
like image 59
Hans Passant Avatar answered Oct 09 '22 16:10

Hans Passant