How to detect number of cores ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
GG
Enthusiast
Enthusiast
Posts: 266
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

How to detect number of cores ?

Post by GG »

Hi all,

Does anybody know a method to determine number of cores ? I would like, in my program, to run as many threads as cores in the machine.
Thanks in advance.
Purebasic 6.12 64 bits - Windows 11 Pro 64 bits 23H2
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: How to detect number of cores ?

Post by KJ67 »

Code: Select all

If GetProcessAffinityMask_(GetCurrentProcess_(), @ProcessMask, @SystemMask)
  For i=0 To 31
    If ProcessMask & (1<<i)
      Count+1
    EndIf
  Next
EndIf
If Count=0: count=1: EndIf
  
Debug Count
The best preparation for tomorrow is doing your best today.
User avatar
GG
Enthusiast
Enthusiast
Posts: 266
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

Re: How to detect number of cores ?

Post by GG »

Thanks KJ67. :D

Another choice : looking for registry : HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor
Purebasic 6.12 64 bits - Windows 11 Pro 64 bits 23H2
Post Reply