Run a search across MPI ranks¶
A gprn or gprd search spends its time in the oracle calls and in the
dense linear algebra of the Gaussian process (GP), and which one dominates
depends on the oracle. Under an MPI launcher the ranks share both. This
page builds a distributed gprn, launches a band search on several ranks,
and sets the flags that choose the factorization and the thread layout. It
assumes the commands of the
pentamer tutorial. For a job on a
cluster allocation, continue with Run on an HPC cluster.
Build an MPI-enabled binary¶
The default Eigen backend has no MPI. -Dlinalg_backend=scalapack or
-Dlinalg_backend=slate links MPI and the distributed code, and
-Duse_mpi=true with any other backend stops Meson with an error. The
scalapack pixi environment (Linux) provides the MPI library and ScaLAPACK:
pixi run -e scalapack smoke-gprn-lj
The task builds gprn with the ScaLAPACK backend and without the optional
external oracles into bld-gprn/ (set GPR_GPRN_BUILD_DIR to change the
directory), then runs a one-iteration Lennard-Jones check on a hydrogen
molecule on a single rank (scripts/setup_gprn_external.sh). Use it first.
The other routes build more:
pixi run -e scalapack build-scalapack-realbuildsgprdandgprnintobuild-scalapack-real/against conda ScaLAPACK. It also builds the metatomic oracle, so the environment must supply libtorch.pixi run -e scalapack build-slatebuildsgprdandgprnagainst SLATE intobuild-slate-real/. The task first builds a tagged SLATE release into~/.cache/gpridge/slate/prefix-<tag>(taskbuild-slate-prefix).Spack with the
mpivariant (Installation) and the EasyBuild recipes with--backend scalapack(EasyBuild guide) build the same backends outside pixi.
Check that a binary links MPI before launching it:
ldd bld-gprn/gprn | grep -i libmpi
No line means a non-MPI build. Such a binary ignores the launcher:
mpirun -np 4 gprn starts four independent copies, and each one prints the
log and writes the output files.
The MPI tests of the repository are the Meson tests whose names end in
_np<N> (_np4 runs mpiexec -np 4 --oversubscribe). List and run a
few after configuring with -Dwith_tests=true (the smoke task sets it):
meson test -C bld-gprn --list | grep _np
meson test -C bld-gprn test_gprn_shutdown_np4 test_oracle_batch_np4 \
test_mpi_thread_support_native_np4
test_gprn_shutdown_np4 starts a four-rank gprn band search and checks
that the exit handlers run on every rank (tests/gpr/native_shutdown.py).
test_oracle_batch_np4 tests the sharing of oracle points.
test_mpi_thread_support_native_np4 checks the thread level that the MPI
library provides. meson test rebuilds every target first, which takes
longer than the smoke task.
Copy the inputs¶
Use the supplied endpoints from the pentamer tutorial.
examples="$GPRIDGE_ROOT/examples/lj-pentamer"
cp "$examples/reactant.con" "$examples/product.con" .
test -s reactant.con -a -s product.con
Run the search¶
Run the search on one rank first. It is the reference for the multi-rank
run, and it needs no MPI. The command adds --oracle-stencil, which
measures a full Cartesian stencil at the saddle: two evaluations per
coordinate, displaced by --oracle-stencil-step (default 0.01 Angstrom),
plus the centre, which is reused when the search has already measured it.
The five atoms have 15 coordinates, so the stencil is 30 oracle calls, the
widest batch of the run:
gprn --reactant reactant.con --product product.con \
--potential lj --nimages 7 --gp-model-profile gprd_zbl \
--oracle-stencil ranks1/stencil.json \
--output ranks1/neb.h5 --write-con ranks1/band.con > ranks1.log 2>&1
grep -E '^(Oracle calls|Barrier energy|Converged|Certified|Cartesian)' ranks1.log
python3 -c "
import json
s = json.load(open('ranks1/stencil.json'))
assert s['complete'] and s['oracle_calls'] == 30 and len(s['energies_eV']) == 31
"
The run on the machine that produced this page printed
Cartesian validation stencil: calls=30 wall_s=<s> complete=1
Oracle calls: <n> (neb=<n>, dimer=0, certificate=0, transition=0)
Barrier energy (eV): <s> (forward: E_saddle - E_reactant)
Converged: yes
Certified: yes
The listed total is the search plus the 30 stencil calls. The search’s share
depends on the stepper; the line
Oracle calls (to convergence): keeps that search count apart from the
stencil. stencil.json holds
positions_A, energies_eV and gradients_eV_per_A, one entry for the
centre and each displaced point (31 entries). The block asserts that the
file is complete and has them. --vibrational-stencil vibrational on this
periodic cell measures 12 directions: 24 stencil calls, 25 energies and 41
oracle calls in all, and the file then carries those directions. That
resolution can call a borderline mode resolved where this full stencil
leaves it unresolved.
Launch the same command under MPI with the binary from the previous
section. Open MPI’s launcher is mpirun; mpiexec is the standard name.
Both read the rank count from -np:
mpirun -np 4 -x PATH -x LD_LIBRARY_PATH -x OMP_NUM_THREADS \
bld-gprn/gprn --reactant reactant.con --product product.con \
--potential lj --nimages 7 --gp-model-profile gprd_zbl \
--oracle-stencil ranks4/stencil.json \
--output ranks4/neb.h5 --write-con ranks4/band.con > ranks4.log 2>&1
grep -E '^(Oracle calls|Barrier energy|Converged|Certified|Cartesian)' ranks4.log
-x NAMEforwards a variable to the ranks. It matters on several nodes, and the repository’s scaling scripts always passPATH,LD_LIBRARY_PATHand the thread variables (scripts/bench_scalapack_scaling.sh).Add
--oversubscribewhen-npexceeds the slots that the launcher sees. The repository’s MPI tests do.On one node Open MPI’s libfabric transport adds a second to
MPI_Finalizeon every rank, so the program setsOMPI_MCA_btl=^ofiwhenOMPI_MCA_btlis unset (managers/MpiLifetime.h). Set the variable yourself to keep another choice.All ranks read the
.confiles, so every node needs the same paths.gprdtakes the same launcher and flags. Under MPI it reads a--gp-seed-archiveonce for the dimer’s process group (test_gprd_seed_archive_np4).
Compare ranks4.log with ranks1.log. The default --linalg-mode reproducible is designed to give the same bits at every rank count, so the
two logs should agree on the barrier and the call counts. The
determinism how-to states what is guaranteed and what can
still change between layouts. Treat a difference as a result to
investigate, and keep both logs.
Choose the factorization, threads and batching¶
Flag |
Default |
Effect |
|---|---|---|
|
|
|
|
1 |
Threads per rank. Eigen and BLAS products stay on one thread in both modes. The count sets the thread team of the kernel and Hessian assembly in a build with parallel STL, and under |
|
1 |
Independent kernel-block threads per rank. Needs a build with parallel STL (TBB, the |
|
0 |
With 0, each rank evaluates all the points it owns in one call. With K, a step is cut into contiguous chunks of K points, and a chunk is the unit of ownership and of the batch call. Set K to the batch size that an engine was traced at when its batched forward depends on the batch composition. |
|
0 |
ScaLAPACK block size. 0 uses the backend default. |
|
0 |
Rows of the ScaLAPACK process grid. 0 uses the backend default. |
The TOML equivalents are [linalg] mode and threads, and [gp]
scalapack_block_size and scalapack_nprow (--config needs a build
with -Duse_capnp=true). --kernel-threads and --oracle-batch-chunk
have no TOML key. The gprn flag reference and the
configuration keys list the rest.
The OpenMP build option does not combine with the distributed backends:
Meson stops on -Duse_openmp=true with scalapack or slate, because
threads on top of ranks oversubscribe the host. Threads inside a rank come
from the two flags above. gprn and gprd set OPENBLAS_NUM_THREADS,
MKL_NUM_THREADS, OMP_NUM_THREADS and RAYON_NUM_THREADS to 1 when they
are unset, and keep the values that you export. Keep ranks times threads
within the cores of the allocation.
Two checks of these options run without MPI. --dump-cli-args prints the
parsed options and the startup lines, then exits with status 0. The line
[startup] linalg reports the factorization and the thread count:
gprn --reactant reactant.con --product product.con --potential lj \
--linalg-mode library --linalg-threads 2 --dump-cli-args \
| grep '^\[startup\] linalg'
--kernel-threads above 1 together with --linalg-threads above 1 is an
error, and the exit status is 1:
status=0
gprn --reactant reactant.con --product product.con --potential lj \
--linalg-threads 2 --kernel-threads 2 --dump-cli-args > threads.log 2>&1 || status=$?
test "$status" -eq 1
cat threads.log
gprd prints the same [startup] linalg line in a normal run, from rank 0.
If a run fails¶
Message or symptom |
Cause and action |
|---|---|
|
The MPI library started the process with a lower thread level ( |
|
Both thread flags are above 1. Set one of them to 1. |
|
|
|
An exception on any rank ends the job through |
Four copies of every log line, or the output files overwritten |
The binary has no MPI. Check it with |
The launcher reports too few slots under Slurm |
The step’s task count is lower than |
See also¶
Run on an HPC cluster: batch scripts, scratch space, restart.
Check run-to-run determinism: what the default factorization guarantees across rank counts.
Task
pixi run -e scalapack bench-mpi-scaling-selfbuilds the working tree and prints the training-step, prediction and variance times at 1 rank and at each count inGPR_SCALAPACK_BENCH_RANKS(default2 4 8 16) for 40 observations (scripts/bench_scalapack_scaling.sh).