简体   繁体   中英

itk 3.20.1 Processor affinity

is there any way to set Processor affinity for ITK (3.20.1) threads. I was looking into ITK::MultiThreader class which has "SetGlobalDefaultNumberOfThreads". 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. However, looking at the MultiThreader header file, I noticed that the implementation relies on the native OS thread mechanisms. 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.

Quoting myself from this answer to another question:

Unfortunately, the posix thread API doesn't provide a way to set cpu affinity for threads. 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.

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 .

Also, the cpuset feature must be built in the kernel, however this should be the case on most platforms with multicore support.

references:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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