============================= 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 :doc:`pentamer tutorial <../tutorials/gprn_lj_pentamer>`. For a job on a cluster allocation, continue with :doc:`Run on an HPC cluster `. What the ranks share -------------------- - Oracle points. The band images, stencil displacements and probes that one step needs form a batch. Each point belongs to one rank, chosen from the point index and the rank count alone, and that rank evaluates it. Afterwards every rank holds the owner's values bit for bit (``gpr/potentials/OracleBatch.h``). The call counters are summed over the ranks (``reduceOracleProviderCalls`` in ``gpr/neb/OCINEBController.cpp``), so the ``Oracle calls:`` line counts each evaluation once. - Dense GP linear algebra. The distributed backend factors the training matrix and solves with it across the ranks. - Everything else. Every rank runs the same driver on the same inputs. Rank 0 prints the log and writes the ``--output`` file, the ``--write-con`` band and the observation archive; the other ranks write none of them. A step with fewer points than ranks leaves some ranks without oracle work. In the pentamer tutorial run, ten outer iterations used 15 oracle calls, so most GP-accelerated steps carry one or two points and extra ranks do not shorten them. Wide batches come from the validation stencil (``--oracle-stencil``) and from ``--nebmode standard``, which evaluates every movable image of the band as one batch at each step. The recorded strong-scaling measurement of a complete GP fit (``paper/jcim/records/fit-scaling/strong.csv``, cell ``11_grignard``, 48 observations, 5376 matrix rows, 47 objective evaluations, ``--linalg-mode reproducible``) shows the trend: the median time falls from 197.1 s on 1 core to 18.8 s on 48 cores of one node and 12.9 s on 96 cores of two nodes, while the parallel efficiency falls to 0.22 and 0.16. Each layout has 3 repetitions, which the manuscript says supports no timing claim, so read the numbers as a trend and measure your own system. A small system with a cheap oracle, such as the pentamer, gains little from ranks. The :doc:`performance guide <../explanation/performance>` discusses where the time goes, and :doc:`Find where a search spends its time ` shows how to measure it on your own run. 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: .. code:: bash 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-real`` builds ``gprd`` and ``gprn`` into ``build-scalapack-real/`` against conda ScaLAPACK. It also builds the metatomic oracle, so the environment must supply libtorch. - ``pixi run -e scalapack build-slate`` builds ``gprd`` and ``gprn`` against SLATE into ``build-slate-real/``. The task first builds a tagged SLATE release into ``~/.cache/gpridge/slate/prefix-`` (task ``build-slate-prefix``). - Spack with the ``mpi`` variant (:doc:`Installation <../getting-started/installation>`) and the EasyBuild recipes with ``--backend scalapack`` (:doc:`EasyBuild guide `) build the same backends outside pixi. Check that a binary links MPI before launching it: .. code:: bash 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`` (``_np4`` runs ``mpiexec -np 4 --oversubscribe``). List and run a few after configuring with ``-Dwith_tests=true`` (the smoke task sets it): .. code:: bash 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. .. code:: bash 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: .. code:: bash 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= complete=1 Oracle calls: (neb=, dimer=0, certificate=0, transition=0) Barrier energy (eV): (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``: .. code:: bash 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 NAME`` forwards a variable to the ranks. It matters on several nodes, and the repository's scaling scripts always pass ``PATH``, ``LD_LIBRARY_PATH`` and the thread variables (``scripts/bench_scalapack_scaling.sh``). - Add ``--oversubscribe`` when ``-np`` exceeds 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_Finalize`` on every rank, so the program sets ``OMPI_MCA_btl=^ofi`` when ``OMPI_MCA_btl`` is unset (``managers/MpiLifetime.h``). Set the variable yourself to keep another choice. - All ranks read the ``.con`` files, so every node needs the same paths. - ``gprd`` takes the same launcher and flags. Under MPI it reads a ``--gp-seed-archive`` once 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 :doc:`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 ---------------------------------------------- .. table:: +------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Flag | Default | Effect | +==============================+==================+==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================+ | ``--linalg-mode MODE`` | ``reproducible`` | ``reproducible`` factors, solves and inverts with the tile-ordered kernels of this repository, designed to give the same bits at every rank and thread count. Each rank then computes the HS-SVD kernel eigensolve and its basis product whole, with Eigen's self-adjoint solver. ``library`` calls the ScaLAPACK or SLATE routines. The host eigensolve stays on that same solver. Across ranks, ScaLAPACK ``pdsyev`` runs from order 1 when unconstrained reductions are enabled, and the basis product is distributed from order 512. Library rounding follows the process grid and the BLAS. | +------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``--linalg-threads N`` | 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 ``reproducible`` it also runs independent tiles of the factorization and the solves in parallel. | +------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``--kernel-threads N`` | 1 | Independent kernel-block threads per rank. Needs a build with parallel STL (TBB, the ``use_stdpar`` option) and ``--linalg-threads 1``. | +------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``--oracle-batch-chunk K`` | 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. | +------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``--scalapack-block-size N`` | 0 | ScaLAPACK block size. 0 uses the backend default. | +------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``--scalapack-nprow N`` | 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 :doc:`gprn flag reference <../reference/cli_reference_gprn>` and the :doc:`configuration keys <../reference/config_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: .. code:: bash 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: .. code:: bash 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 -------------- .. table:: +--------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Message or symptom | Cause and action | +================================================================================================================================+==============================================================================================================================================================================================+ | ``distributed execution requires MPI_THREAD_FUNNELED thread support`` or ``SLATE requires MPI_THREAD_MULTIPLE thread support`` | The MPI library started the process with a lower thread level (``gpr/linalg/MpiThreading.h``). Use an MPI library built with thread support, and run ``test_mpi_thread_support_native_np4``. | +--------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``parallel kernel blocks require --linalg-threads 1`` | Both thread flags are above 1. Set one of them to 1. | +--------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``kernel threads require a positive count and parallel STL support`` | ``--kernel-threads`` is above 1 on a build without TBB. Leave it at 1, or rebuild with TBB (``-Duse_stdpar=enabled``). | +--------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``gprn: error: ...`` on one rank, then the whole job ends | An exception on any rank ends the job through ``MPI_Abort``, with status 1 (``reportFatal`` in ``managers/MpiLifetime.h``). Read the first ``error:`` line in the output of every rank. | +--------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Four copies of every log line, or the output files overwritten | The binary has no MPI. Check it with ``ldd``. | +--------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | The launcher reports too few slots under Slurm | The step's task count is lower than ``-np``. See :doc:`Run on an HPC cluster ` . | +--------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ See also -------- - :doc:`Run on an HPC cluster `: batch scripts, scratch space, restart. - :doc:`Check run-to-run determinism `: what the default factorization guarantees across rank counts. - :doc:`Performance guide <../explanation/performance>` and :doc:`Find where a search spends its time `. - Task ``pixi run -e scalapack bench-mpi-scaling-self`` builds the working tree and prints the training-step, prediction and variance times at 1 rank and at each count in ``GPR_SCALAPACK_BENCH_RANKS`` (default ``2 4 8 16``) for 40 observations (``scripts/bench_scalapack_scaling.sh``).