c++ - 为什么在 Ubuntu VirtualBox 上只报告一个内核(使用 std::async 时发现)?
问题描述
我在 VirtualBox 上的 Ubuntu 上玩 std::async() 。出于某种原因,两个任务的 std::asyc() 我仍然没有得到超过 100% 的 CPU 使用率。我已经提到了用于启动异步任务的 std::launch:async 标志。我期待超过 100% 的使用率,因为我有六核 AMD ryzen 5。当我在 ubuntu 上打印 cpu 信息时,我得到了关注
#include<iostream>
#include<random>
#include<set>
#include<algorithm>
#include<future>
std::set<int> unique_random(uint32_t numElem)
{
std::set<int> retVal;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dist(0, numElem-1);
std::generate_n(std::inserter(retVal, retVal.end()), numElem, [&](){ return dist(gen);});
return retVal;
}
int main()
{
std::cout << "uniue random numbers in first run : " << std::async(std::launch::async, unique_random, 1000000).get().size() << '\n' <<"uniue random numbers in Second run : "<< std::async(std::launch::async, unique_random, 1000000).get().size() <<'\n';;
return 0;
}
编译:g++ async_test.cpp -pthread -o3
时间度量:/usr/bin/time ./a.out
#cat /proc/cpuinfo
2552ms Fri 29 May 2020 02:15:08 AM UTC
processor : 0
vendor_id : AuthenticAMD
cpu family : 23
model : 8
model name : AMD Ryzen 5 2600X Six-Core Processor
stepping : 2
microcode : 0x6000626
cpu MHz : 3593.248
cache size : 512 KB
physical id : 0
siblings : 1
core id : 0
***cpu cores : 1***
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq monitor ssse3 cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm cr8_legacy abm sse4a misalignsse 3dnowprefetch ssbd vmmcall fsgsbase avx2 rdseed clflushopt arat
bugs : fxsave_leak sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips : 7186.49
TLB size : 2560 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management:
在这里,如果您看到它只报告 1 个核心。所以我知道为什么我的 CPU 使用率没有超过 100%,但为什么 Ubuntu 只显示 1 个核心?
是 VirtualBox 的一些错误还是我在这里遗漏了什么?
谢谢
解决方案
推荐阅读
- postgresql - Postgresql:允许来自同一个上传的重复,但不允许来自下一个
- r-markdown - 如何从观星者表中排除标准误差?
- javascript - 我们是否在 webaudio 中使用 createMediaStreamSource 获取所有数据?
- android - 无法解决方法 getAutocompletePredictions
- linux - 为什么“/bin/sh cd /root/eos/”不起作用,但“/bin/sh -c ls && cd /root/eos/”在centos中运行良好
- go - golang gin 加载 html 超时
- php - 未定义变量:Laravel
- javascript - 无法在 node.js 中动态访问 POST 参数
- c# - 使用 RestSharp 反序列化 JSON 响应导致空对象
- excel - 用剪贴板中的图片替换电子邮件中的文本