[fpc-pascal] Single threaded application on multicore CPU

Torsten Bonde Christiansen tc at epidata.info
Wed Jun 22 09:07:47 CEST 2016


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
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.


More information about the fpc-pascal mailing list