HowTo Find the Number of CPU Cores on the Server

Version 2

    When compiling, it is recommended to use all CPU cores to make things faster.

     

    1. To find the number of cores (and other related CPU parameters) on your server, run lscpu.

    # lscpu

    Architecture:          x86_64

    CPU op-mode(s):        32-bit, 64-bit

    Byte Order:            Little Endian

    CPU(s):                16

    On-line CPU(s) list:   0-15

    Thread(s) per core:    2

    Core(s) per socket:    8

    Socket(s):             1

    NUMA node(s):          1

    Vendor ID:             GenuineIntel

    CPU family:            6

    Model:                 62

    Model name:            Intel(R) Xeon(R) CPU E5-2640 v2 @ 2.00GHz

    Stepping:              4

    CPU MHz:               1219.726

    BogoMIPS:              4003.81

    Virtualization:        VT-x

    L1d cache:             32K

    L1i cache:             32K

    L2 cache:              256K

    L3 cache:              20480K

    NUMA node0 CPU(s):     0-15

     

    2. When writing a script and you need to extract the number of CPU cores, you can echo the parameter nproc to obtain the number.

    # echo $(nproc)

    16

     

    Usage example:

    # make –j $(nproc)

    ...

    # make –j $(nproc) modules_install

    ...

    # make –j $(nproc) install

    ...