- Is it possible to programmatically map specific instructions (or event a complete process) to be executed on a designated processor or core (assuming we have more than one processor or core) ?
eg. (I want my program to execute certain instruction likemov al, 5
or a block of code on processor 1). - Can we use parallel API (eg. MPI Message Passing Interface) to do so ?
Asked
Active
Viewed 112 times
1

Cœur
- 37,241
- 25
- 195
- 267

Ibrahim Najjar
- 19,178
- 4
- 69
- 95
-
2You need to provide ALOT more detail - an OS, a programming language, etc. A processor architecture if necessary. – Dlongnecker Jun 22 '11 at 20:40
-
I want to know if this can be done at all, no matter the OS, programming language used or the processor architecture ? – Ibrahim Najjar Jun 22 '11 at 20:53
2 Answers
3
On many OSes you can designate a set of processors on which a thread or process may run. This is called the "CPU affinity" or "processor affinity". If this "set" contains only one element then the thread or process will run exclusively on the specified processor.
On Linux, this is done with the sched_setaffinity
call; on Windows the call is SetThreadAffinityMask
.
Note that if the code is currently running on a processor not included in the permitted set then setting the affinity may cause a context switch as the process/thread is migrated.

Anthony Williams
- 66,628
- 14
- 133
- 155
1
AFAIK that is possible
In the .net you can set the thread affinity "in which core the thread should running" check this

Community
- 1
- 1

Jalal Said
- 15,906
- 7
- 45
- 68