You cannot use more than half of the total available thread in the CPU

I am testing a program on a server running 64-bit Windows Server 2008 R2 Enterprise and has 4 Intel E7-4870 processors, a total of 40 cores and 80 available threads (I can see 80 CPU usage graphs in Windows Task Manager).

The program code looks like this:

numlist is List contains hundreds of numbers, each of which is a parameter that will be used in some calculation

Parallel.ForEach(numlist, num => { // do some calculation using parameter = num }); 

The problem is that when I run this program on the server, it is shown that only half of the available threads are used in the Windows task manager (of course, the CPU usage is shown at 50%), and the remaining 40 are completely unused and idle.

I also tested the same program on another server, which has only 2 processors and only 24 available threads, and all 24 threads will be fully used, and CPU usage will be shown at 100%.

Is there a way to make a 40-core processor server to run this program and fully use all of its avaialable 80 threads (or about 80 threads)? Performance is not good enough when only 50% of the CPU resources are used.


Here is the complete code of the program that I am testing:

 namespace Test { internal class Program { private static void Main(string[] args) { Console.WriteLine("Press any key to start"); Console.ReadLine(); List<int> numlist = new List<int>(); for (int i = 0; i < 100; i++) { numlist.Add(i); } Parallel.ForEach(numlist, num => { while (true) { num++; } }); } } } 

when it runs on a server with two Intel X5690 processors (24 threads total), all 24 threads are used, and CPU usage is shown at 100%;

But when I run it on a server with 4 processors with 80 threads, only 40 threads are used, and CPU usage is only 50%. Are there any compiler settings related to this?

+6
source share
1 answer

Depending on the type of work, hyper threading does not always help. With many types of pure mathematical operations, each core can process only one work item, and not 2, as the number of threads suggested by the processor.

Hyper-threads are not really separate kernels, therefore, the instructions that are executed on them do not always lead to an increase. This is discussed here :

Depending on the configuration of the cluster and, most importantly, the nature of the application running in the cluster, the performance gain may vary or even be negative. The next step is to use performance tools to understand which areas contribute to increased productivity and which areas contribute to reduced productivity.

Hyper-threading tends to increase overall productivity by 30% at best. For this, you usually need different CPU commands pushing each thread on the kernel, so the kernel can work fine. When you perform the same calculation in parallel in many threads, "processor threads" with a multi-threaded thread, you often will not see an advantage compared to a single process running on the kernel.

This could also be due to the fact that you are using managed code that will be limited to processor group 0 because the CLR does not use the new NUMA instructions in Windows 2008 R2. Thus, if your system is configured so that processor group 0 is 40 processors and the remaining 40 are divided into processor group 1, you can saturate the entire first processor group with this process. For more information, see How to get started with a multi-core processor: parallel processing that you can use .

+7
source

Source: https://habr.com/ru/post/952616/


All Articles