Open MPIではデフォルトで物理コア数だけしかプロセスが立ち上がらない。
それだけならまだいいが、ハードウェアスレッドを活用しようと論理コアの数だけプロセスを立ち上げようとするとエラーになるのが良くない。
例えば2コア4スレッド(ハードウェアスレッド、SMT)のマシンでは2プロセスを超えているとエラーになる:
$ mpiexec -n 4 hostname
--------------------------------------------------------------------------
There are not enough slots available in the system to satisfy the 4
slots that were requested by the application:
hostname
Either request fewer procs for your application, or make more slots
available for use.
A "slot" is the PRRTE term for an allocatable unit where we can
launch a process. The number of slots available are defined by the
environment in which PRRTE processes are run:
1. Hostfile, via "slots=N" clauses (N defaults to number of
processor cores if not provided)
2. The --host command line parameter, via a ":N" suffix on the
hostname (N defaults to 1 if not provided)
3. Resource manager (e.g., SLURM, PBS/Torque, LSF, etc.)
4. If none of a hostfile, the --host command line parameter, or an
RM is present, PRRTE defaults to the number of processor cores
In all the above cases, if you want PRRTE to default to the number
of hardware threads instead of the number of processor cores, use the
--use-hwthread-cpus option.
Alternatively, you can use the --map-by :OVERSUBSCRIBE option to ignore the
number of available slots when deciding the number of processes to
launch.
素直にこれに従って--use-hwthread-cpus
オプションをmpiexec
に毎回指定してあげてもいいのだが、できる限りmpiexec
のオプション周りはMPI実装非依存な形で保っておきたい。
上記のエラーメッセージに書かれていないが、MCAパラメタを設定することでデフォルトで--use-hwthread-cpus
をonにすることが可能。
Open MPIのMCAパラメタの一覧を確認するには:
ompi_info --param all all --level 9
ちなみにOpen MPI v5系ではランタイムがORTEというものからPRRTEに変わっており、そのPRRTEのMCAパラメタは以下に移動している:
prte_info --param all
v5系ではprte_set_default_slots
というパラメタが見つかると思うので、以下のように環境変数を設定する:
export OMPI_MCA_prte_set_default_slots=hwthreads
v4以前ではPRRTEではなくORTEなのでorte_set_default_slots
の名前である:
export OMPI_MCA_orte_set_default_slots=hwthreads
こういうデフォルトのMCAパラメタは~/.openmpi/mca-params.conf
に置いておいてもいいらしい。
詳しくは: https://docs.open-mpi.org/en/v5.0.x/mca.html#configuration-files
結果、2コア4スレッドの環境でも以下のように4プロセス立ち上げられる:
$ mpiexec -n 4 hostname
fv-az1385-855
fv-az1385-855
fv-az1385-855
fv-az1385-855