numactl --physcpubind

筅森魡賤 提交于 2019-11-30 07:35:22
osgx

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.

So, threads are allowed to run on any CPU from the cpuset, migration is allowed between any cpu from 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.

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

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

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: 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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!