[fpc-pascal] Single threaded application on multicore CPU

Lukasz Sokol el.es.cr at gmail.com
Wed Jun 22 10:09:28 CEST 2016


On 22/06/16 08:07, Torsten Bonde Christiansen wrote:
> On 2016-06-22 09:02, LacaK wrote:
>> Hi *,
>>
>> may be that this question is bit off-topic here, but I am sure, that here are experts, which know answer ;-)
>>
>> I have simple Lazarus/FPC application (with no explicit threads) which does intensive calculations (local thresholding with big window size) on image, which is stored into memory as 2D byte array.
>> (so only memory access is done and some integer calculations)
>>
>> When I run this application and look at Task Manager or Resource Monitor I see, that all 4 cores "are used" (at least performance graph shows usage or in other words activity in graph increasees)
>> Total CPU usage is <= 25% (which points out to fact, that only 1/4 cores is used)
>>
>> Why this ? As far as I expect, that single threaded application should use only one core, so I would expect activity only on one core not on all four cores
>> (I know that in theory CPU can switch single thread between cores, but I doubt that this is case (as switching has extra cost)... or is ?)
> 
> Nailed it right there....
> 
> All modern CPU automatically swaps running threads (unless affinity is set) to other cores in case there is a high load. This is done from a

^^^^^^^^^^^^^^^^^ s/CPU/OS Kernel ;)

> heat perspective, since running on a single cores will make a local heat spot on the dye - a things which is not prefered and also not really
> cost effient.
> 
>> (Btw: When I set affinity to only one core, then this core is 100% and others are 0% as expected)
>>
> 
> -Torsten.

-L.



More information about the fpc-pascal mailing list