Pinning, the binding of a process or thread to a specific core, can improve the performance of your code.
You can insert the MPI function mpi_get_processor_name and the Linux C function sched_getcpu into your source code to check process and/or thread placement. The MPI function mpi_get_processor_name returns the hostname an MPI process is running on (to be used for MPI and/or MPI+OpenMP codes only). The Linux C function sched_getcpu returns the processor number the process/thread is running on.
If your source code is written in Fortran, you can use the C code mycpu.c, which allows your Fortran code to call sched_getcpu. The next section describes how to use the mycpu.c code.
C Program mycpu.c
#include <utmpx.h>
int sched_getcpu();
int findmycpu_ ()
{
int cpu;
cpu = sched_getcpu();
return cpu;
}
Compile mycpu.c as follows to produce the object file mycpu.o:
The following PBS script provides an example of running the hybrid MPI+OPenMP code across two nodes, with 2 MPI processes per node and 4 OpenMP threads per process, and using the mbind tool to pin the processes and threads.