Page 1 of 1

How to detect number of cores ?

Posted: Thu Jun 10, 2010 4:53 pm
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.

Re: How to detect number of cores ?

Posted: Thu Jun 10, 2010 4:58 pm
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

Re: How to detect number of cores ?

Posted: Thu Jun 10, 2010 5:06 pm
by GG
Thanks KJ67. :D

Another choice : looking for registry : HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor