I was wondering if there was an easy way to set processor affinity when using PGI (or rather, if the PGI tools have their own way to set it) with MPI (mpich)
Or should I just use sched_setaffinity() tools (or taskset tools from the shell)?
You can use taskset, numctl, or the PGI environment variables “MP_BIND” and “MP_BLIST”. However, in all cases to use these with MPI you need to set them individually per process. Typically this is done by writing a wrapper shell script which sets the appropriate environment or utility options and then launches the program. For example, here’s a C shell script for use with MPICH2 and two processes.
$ cat run.csh
setenv MP_BIND YES
if ($PMI_RANK == 0) then
setenv MP_BLIST 0
setenv MP_BLIST 1
$ mpiexec -np 2 run.csh a.out
“PMI_RANK” is set by the MPICH2 driver. Note that not every MPI implementation will have it’s own environment variable to define the rank. Please consult the documentation of your MPI implementation for details.