在Linux/macOS中,如何使N个执行同一程序的程序在100%的不同内核下运行? [英] How to make N executions of the same program run at different cores at 100% in Linux/macOS?

查看:165
本文介绍了在Linux/macOS中,如何使N个执行同一程序的程序在100%的不同内核下运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I run different instances of the same program in different cores at 100%?

我正在使用OS High Sierra 10.13.6的iMac Pro(2017)中运行C ++ 11代码.相应的可执行文件称为"bayesian_estimation".

I am running a C++11 code in an iMac Pro (2017) with OS High Sierra 10.13.6. The corresponding executable is called 'bayesian_estimation'.

当我运行该程序的一个实例时,其中一个核心正在100%完成该任务,如您在此处看到的那样:

When I run one instance of this program, one of the cores is doing that task at 100%, as you can see here:

如果我运行更多实例,则每个实例的CPU%下降.但是大多数核心仍然闲置!为什么不使用它们?例如,查看当3个'bayesian_estimation'进程正在运行时会发生什么:

If I run more instances, the CPU% of each of them goes down. But most of the cores remain idle! Why are not they being used? See, for example, what happens when 3 'bayesian_estimation' processes are running:

或者当我执行7:

理想情况是在上图中,我希望有7个核心完全繁忙,每个核心都运行一个"bayesian_estimation"进程.

Ideally in the last picture, I would like to have 7 cores completely busy, each of them running one 'bayesian_estimation' process.

我将继续提供可能有助于识别问题的更多信息.我将代码编译如下:

I proceed to give more information that might help to identify the problem. I compiled my code as follows:

g++ -std=c++11 -Wall -g bayesian_estimation.cpp -o bayesian_estimation -O2 -larmadillo

我使用的

所有库和软件包如下:

And all libraries and packages that I have used are the following:

#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在评论中提到的瓶颈的起源.这是由于在Armadillo库中使用代码中的arma_rng::set_seed_random()生成随机数而引起的.如果我删除那行代码,问题就解决了.

I identified the origin of the bottleneck that @bolov mentions in the comments. It arises due to the use of arma_rng::set_seed_random() in the code to generate random numbers with the Armadillo library. If I remove that line of the code, the problem is gone.

发布了一个更深入地研究该问题并提供可复制示例的问题,

A question going deeper into this issue and providing with a reproducible example is posted here.

这篇关于在Linux/macOS中,如何使N个执行同一程序的程序在100%的不同内核下运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆