1
  1. 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 like mov al, 5 or a block of code on processor 1).
  2. Can we use parallel API (eg. MPI Message Passing Interface) to do so ?
Cœur
  • 37,241
  • 25
  • 195
  • 267
Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95

2 Answers2

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