如何在Linux / macOS中以100%的不同内核运行同一程序的N次执行?

问题描述 投票:0回答:1

QUESTION

如何在100%的不同核心中运行同一程序的不同实例?

CONTEXT

我正在使用OS High Sierra 10.13.6在iMac Pro(2017)中运行C ++ 11代码。相应的可执行文件称为“贝叶斯估计”。

当我运行这个程序的一个实例时,其中一个核心以100%执行该任务,如下所示:

enter image description here

如果我运行更多实例,则每个实例的CPU%都会下降。但大多数内核仍处于空闲状态!他们为什么不被使用?例如,请参阅3'beaviesian_estimation'进程运行时会发生什么:

enter image description here

或者当我执行7时:

enter image description here

理想情况下,在最后一张图片中,我希望有7个内核完全忙碌,每个内核都运行一个'bayesian_estimation'进程。

EDIT 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.
c++ performance c++11 parallel-processing
1个回答
0
投票

我确定了@bolov在评论中提到的瓶颈的起源。它的产生是由于在代码中使用arma_rng::set_seed_random()来生成Armadillo库的随机数。如果我删除代码行,问题就消失了。

here发布了一个更深入探讨这个问题并提供可重复示例的问题。

© www.soinside.com 2019 - 2024. All rights reserved.