zoukankan      html  css  js  c++  java
  • Linux check whether hyperthreading is enabled or not

    There parameters need to be obained: no. of physical CPU; no. of cores on each CPU; no. of all threads.

    In my case, the CPU name: Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz

    (1) Check the number of physical CPU

    # cat /proc/cpuinfo | grep "physical id" | sort | uniq

    physical id : 0

    physical id : 1

    //// Here we can see the number of physical CPU is 2. Each physical CPU has its own fan.

    (2) Check the number of logical cores on each CPU

    # cat /proc/cpuinfo | grep "cores" | uniq

    cpu cores : 10

    //// Here each physical CPU has 10 cores.

    (3) Check the number of all threads

    # cat /proc/cpuinfo | grep "processor" | wc -l

    40

    //// After obtaining above three parameters, now we can judge whether the hyperthreading is enabled or not.

    In the case withou hyperthreading, number of all threads= no. of physical CPU * no. of cores on each CPU * 1, then there is only one thread on each core.

    When hyperthreading is enabled, for example, N threads are available on each core. Then the following relationship can be achived:

    number of all threads= no. of physical CPU * no. of cores on each CPU * N.

    NOTE: OpenMP

    The OpenMP parallel language can also be used to check the number of threads per core.

    #include "stdio.h"
    #include "omp.h"
    
    int main()
    {
        int num_thread, myid;
        
        #pragma omp parallel
        {
            num_threads= omp_get_num_threads();    // get the total number of threads on one core
            myid= omp_get_thread_num();            // get the ID of the current thread
            printf("
    Hello world from the thread %d out of %d threads!");
        }    
        return 0;
    }

    Use the following command to compile the C file "hello.c":

    $ gcc -fopenmp -o run.o hello.c

    $ ./run.o

  • 相关阅读:
    javaScript类型和对象
    极客时间买课全额返现
    极客时间返利课程返利文字版
    负责范围
    list查询
    缺件修改
    修改信息
    Windows系统解决占用端口问题
    mysql系列——常用的几十个函数详解(六)
    史上最全日期时间类讲解
  • 原文地址:https://www.cnblogs.com/alliance/p/8193591.html
Copyright © 2011-2022 走看看