diff --git a/flow/templates/base_script.sh b/flow/templates/base_script.sh index b2a3aeedb..5b9dae2bf 100644 --- a/flow/templates/base_script.sh +++ b/flow/templates/base_script.sh @@ -20,6 +20,8 @@ cd {{ project.config.project_dir }} {% for operation in operations %} # {{ "%s"|format(operation) }} +{% block pre_operation scoped %} +{% endblock %} {{ operation.cmd }}{{ cmd_suffix }} {% if operation.eligible_operations|length > 0 %} # Eligible to run: diff --git a/flow/templates/stampede2.sh b/flow/templates/stampede2.sh index a5756ace8..2d76ddd3e 100644 --- a/flow/templates/stampede2.sh +++ b/flow/templates/stampede2.sh @@ -55,34 +55,17 @@ export LAUNCHER_JOB_FILE={{ launcher_file }} $LAUNCHER_DIR/paramrun rm {{ launcher_file }} {% else %} -{% set cmd_suffix = cmd_suffix|default('') ~ (' &' if parallel else '') %} -{% for operation in operations %} - -# {{ "%s"|format(operation) }} -{{ "_FLOW_STAMPEDE_OFFSET_=%d "|format(operation.directives['nranks']|return_and_increment) }}{{ operation.cmd }}{{ cmd_suffix }} -{% if operation.eligible_operations|length > 0 %} -# Eligible to run: -{% for run_op in operation.eligible_operations %} -{# The split/join handles multi-line cmd operations. #} -# {{ "\n# ".join(run_op.cmd.strip().split("\n")) }} -{% endfor %} -{% endif %} -{% if operation.operations_with_unmet_preconditions|length > 0 %} -# Operations with unmet preconditions: -{% for run_op in operation.operations_with_unmet_preconditions %} -# {{ "\n# ".join(run_op.cmd.strip().split("\n")) }} -{% endfor %} -{% endif %} -{% if operation.operations_with_met_postconditions|length > 0 %} -# Operations with all postconditions met: -{% for run_op in operation.operations_with_met_postconditions %} -# {{ "\n# ".join(run_op.cmd.strip().split("\n")) }} -{% endfor %} -{% endif %} -{% endfor %} +{# Only the pre_operation block is overridden, all other behavior is inherited from base_script.sh #} +{{ super () -}} {# We need to reset the environment's base offset in between script generation for separate bundles. #} {# Since Jinja's bytecode optimizes out calls to filters with a constant argument, we are forced to #} {# rerun this function on the environment's base offset at the end of each run to return the offset to 0. #} {{ "%d"|format(environment.base_offset)|decrement_offset }} {% endif %} {% endblock %} + +{# This override needs to happen outside the body block above, otherwise jinja2 doesn't seem to #} +{# respect block scope and the operations variable is left undefined. #} +{% block pre_operation %} +export _FLOW_STAMPEDE_OFFSET_={{ "%d"|format(operation.directives['nranks']|return_and_increment) }} +{% endblock %} diff --git a/tests/template_reference_data.tar.gz b/tests/template_reference_data.tar.gz index 9d3e4560b..461c60f3f 100644 Binary files a/tests/template_reference_data.tar.gz and b/tests/template_reference_data.tar.gz differ