Skip to content

How to bind created threads to specific CPU cores? just like pthread_setaffinity_np #6505

Answered by Pansysk75
phil-skillwon asked this question in Q&A
Discussion options

You must be logged in to vote

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

// launch tasks on threads using numbering 0,1,2,3...0,1,2,3
std::size_t threads = hpx::…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@phil-skillwon
Comment options

@hkaiser
Comment options

@phil-skillwon
Comment options

@hkaiser
Comment options

Answer selected by phil-skillwon
Comment options

You must be logged in to vote
1 reply
@phil-skillwon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants