[英]How to make N executions of the same program run at different cores at 100% in Linux/macOS?
如何以100%在不同的内核中运行同一程序的不同实例?
我正在具有OS High Sierra 10.13.6的iMac Pro(2017)中运行C ++ 11代码。 相应的可执行文件称为“ bayesian_estimation”。
当我运行该程序的一个实例时,其中一个核心正在100%完成该任务,如下所示:
如果我运行更多实例,则每个实例的CPU%下降。 但是大多数核心仍然闲置! 为什么不使用它们? 例如,查看运行3个'bayesian_estimation'进程时发生的情况:
或者当我执行7时:
理想情况下,在上一张图中,我希望有7个核心完全繁忙,每个核心都运行一个“ bayesian_estimation”进程。
我将继续提供可能有助于识别问题的更多信息。 我将代码编译如下:
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.
我确定了@bolov在评论中提到的瓶颈的根源。 出现这种情况是由于在代码中使用了arma_rng::set_seed_random()
通过Armadillo库生成随机数。 如果删除该行代码,问题就消失了。
在此发布了一个深入探讨该问题并提供可重现示例的问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.