How to bind created threads to specific CPU cores? just like pthread_setaffinity_np #6505
-
Our application is migrating from pthreads to HPX, but some thread functions need to be manually bound to specific CPU cores, i.e., setting the thread's CPU affinity. However, I haven't found similar usage examples in HPX documentation. How can I bind the created threads to specific CPU cores in HPX? just like pthread_setaffinity_np |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@phil-skillwon There might be better ways to achieve what you want, depending on why you need CPU affinity in the first place, but I recently had to do something similar so here's one mechanism related to what you need: The thread_schedule_hint can be used to schedule an hpx thread on a specific queue in the hpx scheduler (each queue is associated with a single physical core). If you are using hpx::async to launch tasks, you can pass an executor with an appropriate (or decorate an existing executor using If not using hpx::async, the hpx/examples/throttle/throttle/server/throttle.cpp Lines 121 to 127 in d08354d Using Also, in contrast to Finally, there are also thread pools and the resource partitioner, which can be used to control which hardware resources you are using, but I'm not too familiar with those. |
Beta Was this translation helpful? Give feedback.
-
As a side note, @Pansysk75 and I discussed yesterday how we could implement an API similar to |
Beta Was this translation helpful? Give feedback.
@phil-skillwon There might be better ways to achieve what you want, depending on why you need CPU affinity in the first place, but I recently had to do something similar so here's one mechanism related to what you need:
The thread_schedule_hint can be used to schedule an hpx thread on a specific queue in the hpx scheduler (each queue is associated with a single physical core).
If you are using hpx::async to launch tasks, you can pass an executor with an appropriate
thread_schedule_hint
:hpx/libs/core/resource_partitioner/tests/unit/scheduler_binding_check.cpp
Lines 64 to 75 in d08354d