[CMake] Getting the number of processor

Mathieu Malaterre mathieu.malaterre at gmail.com
Tue Jun 3 11:15:19 EDT 2008


Goal: be able to automate the -j flag option for make. In my ctest
script I would say:

...
IF("Unix Makefiles")
  GET_NUMBER_OF_PROCESSORS(numproc)
  SET(option "-j${numproc}")
ENDIF("Unix Makefiles")
...

I saw that kwsys/SystemInformation had an APi for that, but I have not
check how to use it from ctest.

Thanks!
-Mathieu

Ref:
$ cat /proc/cpuinfo
...
processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz
stepping        : 7
cpu MHz         : 1861.916
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 3
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall
nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips        : 3723.93
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:



On Tue, Jun 3, 2008 at 5:03 PM, David Cole <david.cole at kitware.com> wrote:
> (1) What contents are in /proc/cpuinfo?
> (2) What are you getting as output when you use this CMake code?
> (3) What do you expect to get?
>
>
>
> On Fri, May 30, 2008 at 12:33 PM, Mathieu Malaterre
> <mathieu.malaterre at gmail.com> wrote:
>>
>> regex are driving me nuts... could someone please let me know what is
>> wrong with my 'REPLACE' expression.
>>
>> Thanks !
>>
>> FILE(READ /proc/cpuinfo cpuinfo)
>> STRING(REGEX REPLACE "\r?\n" ";" cpuinfo "${cpuinfo}")
>> SET(myoutput "")
>>
>> FOREACH(line ${cpuinfo})
>>  STRING(REGEX MATCH "processor" proc_line ${line})
>>  STRING(REGEX REPLACE
>>    "^processor[ ]+:[ ]+([0-9]+)$"
>>    " \\1 " nline "${line}")
>>  IF(proc_line)
>>  MESSAGE(${nline})
>>    SET(myoutput "${myoutput}\n${nline}")
>>  ENDIF(proc_line)
>> ENDFOREACH(line)
>>
>> MESSAGE("${myoutput}")
>>
>> --
>> Mathieu
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>
>



-- 
Mathieu


More information about the CMake mailing list