简体   繁体   English

itk 3.20.1处理器关联

[英]itk 3.20.1 Processor affinity

is there any way to set Processor affinity for ITK (3.20.1) threads. 有什么方法可以为ITK(3.20.1)线程设置处理器亲和力。 I was looking into ITK::MultiThreader class which has "SetGlobalDefaultNumberOfThreads". 我正在研究具有“ SetGlobalDefaultNumberOfThreads”的ITK :: MultiThreader类。 but i am not finding any function/method which is saying anything about affinity. 但我没有找到任何有关亲和力的功能/方法。

any help would be appreciated.. 任何帮助,将不胜感激..

In the version that I have installed (3.18), it seems that this feature is not supported. 在我安装的版本(3.18)中,似乎不支持此功能。 However, looking at the MultiThreader header file, I noticed that the implementation relies on the native OS thread mechanisms. 但是,在查看MultiThreader头文件时,我注意到该实现依赖于本机OS线程机制。 This means that on linux, pthreads are actually spawned, and pthread_t are directly used for ThreadProcessIdType , which means that you might be able to use the linux proprietary extensions for core affinities. 这意味着在linux上,实际上是生成了pthread,而pthread_t直接用于ThreadProcessIdType ,这意味着您可以使用linux专有扩展来实现核心亲和力。

Quoting myself from this answer to another question: 这个答案中引出自己来回答另一个问题:

Unfortunately, the posix thread API doesn't provide a way to set cpu affinity for threads. 不幸的是,posix线程API没有提供一种设置线程cpu亲和力的方法。 You may use the non portable extension provided on the linux platform pthread_attr_setaffinity_np , with the cpuset family of functions to configure a thread affinity. 您可以将linux平台pthread_attr_setaffinity_np上提供的非便携式扩展与cpuset系列功能一起使用,以配置线程关联。

Since the thread will be already running, you will need to get the thread attributes before being able to set its affinity. 由于线程已经在运行,因此需要先获取线程属性,然后才能设置其亲和力。 Linux provides one more non portable function for that: pthread_getattr_np . Linux为此提供了另一个不可移植的功能: pthread_getattr_np

Also, the cpuset feature must be built in the kernel, however this should be the case on most platforms with multicore support. 另外,必须在内核中内置cpuset功能,但是在大多数支持多核的平台上都是这种情况。

references: 参考资料:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM