From 274e7e957ceba37f7e6026c104acd4f027796001 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Fri, 9 Oct 2026 07:14:59 -0700 Subject: [PATCH] Fail fast on Flux MPI launches outside an allocation --- toolchain/templates/default.mako | 7 +++++++ toolchain/templates/include/helpers.mako | 7 +++++++ toolchain/templates/tuo.mako | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/toolchain/templates/default.mako b/toolchain/templates/default.mako index 2d05d3ab3c..5d9c546e3f 100644 --- a/toolchain/templates/default.mako +++ b/toolchain/templates/default.mako @@ -36,6 +36,13 @@ if engine == 'batch': else ok ":) Selected MPI launcher $MAGENTA$binary$COLOR_RESET. Use$MAGENTA --binary$COLOR_RESET to override." fi + + % if engine == 'interactive': + # On Flux systems, srun is a wrapper that submits a batch job outside an allocation. + if [ "$binary" == "srun" ] && command -v flux > /dev/null; then + ${helpers.require_flux_allocation()} + fi + % endif % endif % for target in targets: diff --git a/toolchain/templates/include/helpers.mako b/toolchain/templates/include/helpers.mako index 58e34a3666..3fd21baa98 100644 --- a/toolchain/templates/include/helpers.mako +++ b/toolchain/templates/include/helpers.mako @@ -45,6 +45,13 @@ END % endif +<%def name="require_flux_allocation()"> + if [ -z "$FLUX_ENCLOSING_ID" ]; then + error ":( Not inside a Flux allocation: each launch would be submitted as its own batch job. Run inside 'flux alloc ...', use '-e batch', or pass --no-mpi.\n" + exit 1 + fi + + <%def name="template_epilogue()"> % if os.name != 'nt': #> diff --git a/toolchain/templates/tuo.mako b/toolchain/templates/tuo.mako index 74c6dc4fc5..47a1cc9fa6 100644 --- a/toolchain/templates/tuo.mako +++ b/toolchain/templates/tuo.mako @@ -37,6 +37,10 @@ echo export HSA_XNACK=0 +% if mpi and engine == 'interactive': + ${helpers.require_flux_allocation()} +% endif + % for target in targets: ${helpers.run_prologue(target)}