c++检测cpu内核的数目
2023-09-14 09:01:35 时间
以下代码摘自OpenCV源码中的parallel.cpp文件, 翻看源码的时候看到,里面的注释说的事很重要,记录一下。
static
int getNumberOfCPUs_()
{
/*
* Logic here is to try different methods of getting CPU counts and return
* the minimum most value as it has high probablity of being right and safe.
* Return 1 if we get 0 or not found on all methods.
*/
#if defined CV_CXX11 \
&& !defined(__MINGW32__) /* not implemented (2020-03) */ \
/*
* Check for this standard C++11 way, we do not return directly because
* running in a docker or K8s environment will mean this is the host
* machines config not the containers or pods and as per docs this value
* must be "considered only a hint".
*/
unsigned ncpus = std::thread::hardware_concurrency(); /* If the value is not well defined or not computable, returns 0 */
#else
unsigned ncpus = 0; /* 0 means we have to find out some other way */
#endif
#if defined _WIN32
相关文章
- C++ 练气期之二维数组与矩阵运算
- 【笔记】《深入理解C++11》(下)
- 深入理解C++11_c++ string char
- c++ auto类型_auto C++
- C++回炉之_C++PrimerPlus_第十三章 类继承
- c++学生管理系统源代码_学校运营管理系统
- c++的链表-链表入门(C++)
- C/C++ 使用CRC检测磁盘文件完整性
- C/C++ Qt 命令行版网络通信
- 如何用Swift重写C++/ObjC代码库,并将其缩减70%
- 为什么永远不会有语言取代 C/C++?
- C++:哈希:闭散列哈希表
- c++基础篇之C++ 模板
- cpu探查Linux内核:查看CPU使用情况(linuxcore查看)
- 优化Linux 内核下CPU性能优化实践(linux内核cpu)
- C++ set用法(STL set用法)详解
- C++ accumulate函数用法详解
- C++数据类型(强制)转换详解
- C++ share_ptr智能指针使用详解
- C++的static关键字及变量存储位置总结
- 基于C/C++时间函数的使用详解
- C++输入一个字符串,把其中的字符按照逆序输出的两种方法解析