发问
如何在100%的不同内核中运行相同程序的不同实例?
上下文
我正在运行一个C++11代码在一个iMac Pro (2017)与OSHighSiera10.13.6。相应的可执行文件称为‘bayesian_估测’。
当我运行这个程序的一个实例时,其中一个核心以100%的速度执行该任务,如下所示:

如果我运行更多的实例,每个实例的CPU%就会下降。但是大部分的核心都是闲置的!为什么他们不被使用?例如,请参见3 'bayesian_estimation‘进程运行时会发生什么情况:

或者当我执行7:

理想情况下,在最后一张照片中,我希望有7个核心完全繁忙,每个核心运行一个'bayesian_estimation‘进程。
编辑1
我将提供更多可能有助于查明问题的信息。我编译了我的代码如下:
g++ -std=c++11 -Wall -g bayesian_estimation.cpp -o bayesian_estimation -O2 -larmadillo我使用过的所有库和包如下:
#include <iostream> // Standard input and output functions.
#include <iomanip> // Manipulate stream input and output functions.
#include <armadillo> // Load Armadillo library.
#include <sys/stat.h> // To obtain information from files (e.g., S_ISDIR).
#include <dirent.h> // Format of directory entries.
#include <vector> // To deal with vectors.发布于 2018-11-08 14:13:16
我确定了@bolov在评论中提到的瓶颈的来源。这是由于在代码中使用arma_rng::set_seed_random()来生成Armadillo库中的随机数。如果我删除这一行代码,问题就消失了。
一个问题深入到这个问题,并提供了一个可重复的例子是张贴here。
https://stackoverflow.com/questions/53205907
复制相似问题