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

  • 相关阅读:
    面试中变相考算法复杂度
    黑马程序猿——JAVA面向对象的特性:封装,继承,多态
    Supermap 组合单值专题图与标签专题图演示样例
    线段树 hdu3642 Get The Treasury
    servlet学习(1)
    Androidbutton事件的五中写法总结
    Java多线程的调度策略
    linux命令行学习-dig(DNS查询器)
    kettle(一)概述
    学习C语言,困难吗?
  • 原文地址:https://www.cnblogs.com/alliance/p/8193591.html
Copyright © 2011-2022 走看看