numactl的--physcpubind [英] numactl --physcpubind

查看:2779
本文介绍了numactl的--physcpubind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用numactl的,具有--physcpubind选项。手册说:

I was using the numactl, with --physcpubind option. manual says:

--physcpubind=cpus, -C cpus
Only execute process on cpus. Etc...

让我们说我有NUMA系统3 NUMA节点,在那里他们每个人有4个内核。 NUMA节点0具有0,1,2,3为核心的数字。 NUMA节点1有4,5,6,7,和NUMA节点2有8,9,10,11。我的问题是让我们说我运行程序如下:

Let's say I have NUMA system with 3 NUMA nodes, where each of them has 4 cores. NUMA node 0 has 0, 1, 2, 3 as core numbers. NUMA node 1 has 4,5,6,7, and NUMA node 2 has 8,9,10,11. My question is let's say I run the program as follows:

export OMP_NUM_THREADS=6
numactl --physcpubind=0,1,4,5,8,9 ./program

即。我将与6个线程在运行了一个程序,我请求他们是在CPU内核0,1,4,5,8,9。例如,如果在程序中的某些点边线0-5被分配的CPU核心0,1,4,5,8,9(设置1)。是有可能,在程序执行线程0中的一些其它点可以在CPU核心9运行,例如,等等?即会不会有CPU核心之间的线程迁移?或线程唯一获得势必CPU内核(如设置1)?谢谢你。

i.e. I'll be running my program with 6 threads and I am requesting them to be on CPU cores 0,1,4,5,8,9. For example, if at some point during the program threads 0-5 are assigned CPU cores 0,1,4,5,8,9 (setup1). Is it possible that at some other point during the program execution thread 0 may be running on CPU core 9 for example, and so forth? I.e. will there be thread migration between CPU cores? Or the threads uniquely get bound to CPU cores (as in setup1)? Thanks.

推荐答案

physcpubind numactl的应的了sched_setaffinity 系统调用,这在过程起动瞬间改变的过程中cpuset(组允许的CPU的)。每个线程都有自己的cpuset,但所有的线程将继承父进程的cpuset值。

physcpubind option of numactl should be an interface to sched_setaffinity system call, which modifies cpuset (set of allowed CPU) of the process at moment of process starting. Each thread will have own cpuset, but all threads will inherit their cpuset value from parent process.

因此​​,线程被允许从cpuset任何CPU上运行,迁移从cpuset任何CPU之间允许的。

So, threads are allowed to run on any CPU from the cpuset, migration is allowed between any cpu from cpuset.

任何线程可以调用了sched_setaffinity或 pthread_setaffinity_np (亲和力改单线程的特定的Linux变种)缩小甚至扩大其cpuset。

Any thread can call sched_setaffinity or pthread_setaffinity_np (linux-specific variant of affinity changing for single thread) to narrow or even to expand its cpuset.

如果你想绑定线程的CPU,在每一个线程使用了sched_setaffinity或pthread_setaffinity_np直接或OpenMP的情况下通过OMP库设置亲和力的 OpenMP和CPU亲和力例如:使用命令(OpenMP的3.1 +)

If you want bind threads to CPUs, use sched_setaffinity or pthread_setaffinity_np directly in every thread, or in case of OpenMP set affinity via OMP library: OpenMP and CPU affinity e.g. with command (OpenMP 3.1+)

export OMP_PROC_BIND=true

我想这OMP库将在OMP库初始化时间选择过程中cpuset循环方式的CPU。

I guess that OMP library will select CPUs in round-robin manner from cpuset of process at time of omp library initialization.

有关libgomp的旧版本 - OMP支持库GCC使用 - 您可以通过允许CPU集与命令:

For older version of libgomp - OMP support library used by GCC - you can pass allowed set of CPU with command:

export GOMP_CPU_AFFINITY=0-1,4-5,8-9

PS:检查你的线程的位置就可以启动并启用最后的CPU使用与场F Ĵ键和 ^ h

PS: to check your threads placement you can start top and enable "Last CPU used" field with f j keys and turn on thread display with H.

这篇关于numactl的--physcpubind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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