Я играл с std :: asyn c () на моем Ubuntu на VirtualBox. По какой-то причине с std :: asy c () для двух задач я все еще не получал использование ЦП более чем на 100%. Я упомянул флаг std :: launch: asyn c для запуска задач asyn c. Я ожидал более 100% использования, так как у меня шесть ядер AMD ryzen 5. Когда я напечатал информацию о процессоре в ubuntu, я получил следующее
#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;
}
Compilation: 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 ядро. Итак, я знаю, почему загрузка ЦП не превышает 100%, но почему Ubuntu показывает только одно ядро?
Это какая-то ошибка с VirtualBox или я чего-то здесь не хватает?
Спасибо