multithreading - Forcing MPI to use a specified no. of cores -


i kinda new mpi, forgive me if trivial question. have quad core cpu. , want run openmpi c++ program uses 2 processes on single core. there way so? if so, how? referred this link on stack overflow which, most probably, says there might way... if so, how can it?

since mpi spawns separate processes, scheduling of processes onto cores generally/usually performed operating system. can still achieve want manually setting affinity of processes specific core.

you can in linux using sched_setaffinity function.

to pin process specific core, can use following approach:

#include <mpi.h> #include <sched.h>  // ...  void pin_to_core(int cpuid) {                                                 cpu_set_t set;                                                            cpu_zero(&set);                                                           cpu_set(cpuid,&set);                                                                                                                                                                                                              sched_setaffinity(0,sizeof(cpu_set_t),&set); }  // ....  int main(int argc, char* argv[]) {     mpi_init(&argc, &argv);     pin_to_core(0); // pin process core 0     // ...     mpi_finalize(); } 

make sure call function after call mpi_init in main function , specify core want pin process to.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -