NumCPULib4Pascal is a Library that enables you to Count the number of CPUs on the current machine.
This Library aims to provide support for those Oses that are not supported by System.CPUCount ( or those in which System.CPUCount
Compile Project, Target: UsageSamples.exe: Success, Hints: 3
NumCPULib.pas(367,24) Hint: Local variable "LSystemAffinityMask" does not seem to be initialized
NumCPULib.pas(366,68) Hint: Local variable "LProcessAffinityMask" does not seem to be initialized
NumCPULib.pas(382,30) Hint: Local variable "LSystemInfo" does not seem to be initialized
501 lines compiled, 0.2 sec, 72560 bytes code, 4196 bytes data
Hmm, it shows 8 on my 4 core (and probably will show 12 on my 6 core) due to hyperthreading. The logical count number is not very useful, usually the number of worker threads to spawn is based on physical count (and in case of hyperthreading a slightly higher percentage on top of that)
is there some way to get the physical count?
is there some way to get the physical count?
I will test the RPi and will report back.
Hi!
There was an example how to count CPUs in the wiki, now it is an empty page. It was at
http://wiki.freepascal.org/Example_of_multi-threaded_application (http://wiki.freepascal.org/Example_of_multi-threaded_application)
It could count only logic CPUs, not physical. It worked on Linux, Darwin, Windows, Solaris and FreeBSD as I remember.
If it helps I can start a search in the deepth of my hardisk - must be somewhere.
Winni
Logical CPU Count is 2
Physical CPU Count is 2
Windows 7 result:QuoteLogical CPU Count is 2
Physical CPU Count is 2
It's okay. But to tell the truth, I have one CPU with two cores. ;)
Works perfectly fine on the Raspberry Pi (all versions)
Used this code, because I could not stand the superfluous format() use ;D ;D
program cpulibtest; uses numcpulib; begin WriteLn('Logical CPU Count is ', TNumCPULib.GetLogicalCPUCount); WriteLn('Physical CPU Count is ', TNumCPULib.GetPhysicalCPUCount); end.
Outputs:
Logical CPU Count is 4 Physical CPU Count is 4
Was this by any chance run in a VM?
Was this by any chance run in a VM?
My english is very weak, so my answer what I understood, so I don't use any virtual machine now, this sample run on my "clean" windows 7 x 64 OS.
And you are sure your PC has just one physical CPU?
And you are sure your PC has just one physical CPU?
I repair the computers in my workplace becuase the local IT cant fix anything, so what do you think, can I know how many cpu sleep in my mainboard? :)
Hi!
Hardware: AMD Ryzen 5 2400 g (4 cores, 8 threads)
OS: Suse Tumbleweed
reports:
Logical CPU Count is 8
Physical CPU Count is 8
What kind of count is going on?
Winni
Hi,
my hardware: AMD Ryzen 5 1500x (4 Cores, 8 Threads),
my OS: Win7 64
report says:
physical 4, logical 8,
so everything is okay!
@Xor-el
The AMD processor page says definitly: 4 cores, 8 threads
The KDE Info Center reports 8 cores!
HardInfo reports 8 processors but doesn't say nothing if physical or logical!
This is a land of confusion ....
Winni
@Xor-el
In the case of linux it seems to be the easiest way to read /proc/cpuinfo. There is a very lot of information, but the two needed values are present:
......
processor : 7
vendor_id : AuthenticAMD
cpu family : 23
model : 17
model name : AMD Ryzen 5 2400G with Radeon Vega Graphics
stepping : 0
microcode : 0x810100b
cpu MHz : 1458.000
cache size : 512 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
.........
That seems to be a secure and easy way.
Winni
NumCPULib4Pascal is a Library that enables you to Count the number of CPUs on the current machine.
This Library aims to provide support for those Oses that are not supported by System.CPUCount ( or those in which System.CPUCount defaults to 1).
NumCPULib4Pascal is a Library that enables you to Count the number of CPUs on the current machine.
This Library aims to provide support for those Oses that are not supported by System.CPUCount ( or those in which System.CPUCount defaults to 1).
Awesome! And thanks! I was researching code for this very thing in June...
@Xor-el
I have one remark:
You designed it with int32 and exceptions.
I would prefer it without exceptions and an unsigned type.
For some platforms that would require maybe a local variable of a signed type.
After all you have a fall-back to one, and it can't be processed at all of there is no processor :D 8-)
@Xor-el
I have one remark:
You designed it with int32 and exceptions.
I would prefer it without exceptions and an unsigned type.
For some platforms that would require maybe a local variable of a signed type.
After all you have a fall-back to one, and it can't be processed at all of there is no processor :D 8-)
@Xor-el
Just tested the version https://github.com/Xor-el/NumCPULib4Pascal/blob/travis/NumCPULib/src/NumCPULib.pas (https://github.com/Xor-el/NumCPULib4Pascal/blob/travis/NumCPULib/src/NumCPULib.pas)
Yeah, now with info from /proc/cpuinfo everythings looks fine.
For my Ryzen is reported
Logical CPU Count is 8
Physical CPU Count is 4
Have a nice day
Winni
@winni, yes I did make some minor changes as regards multiple sockets PC.
was not making a unique count before so duplicates were counted.
Thanks for testing though.
Question, @Xor-el. At present, do you plan to be able to distinguish a system with 2 sockets, each containing quad-core processors, with hyperthreading, vs a single 8-core CPU with hyperthreading?
Both would have 8 physical CPUs and 16 logical CPUs, but it would be nice to be able to distinguish two-socket or four-socket server system.
@ASBzone, might be a research area for me in the future but for now nothing at the moment. :)