• 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

  • 相关阅读:
    SpringCloud高可用和高并发
    时间重要性,我们需要如何利用极致
    Spring是什么 包括SpringBean SpringMVC SpringBoot SpringCloud
    Java 线程的基本使用
    JVM 内存模型
    Java 8 ArrayList 详解
    Java 8 HashMap 源码解析
    Docker 运行 MySQL,使用 docker-compose
    Spring Boot 主从读写分离
    Spring Boot 整合 MyBatis 实现乐观锁和悲观锁
  • 原文地址:https://www.cnblogs.com/alliance/p/8193591.html
Copyright © 2020-2023  润新知