summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorXavier Delaruelle <xavier.delaruelle@cea.fr>2023-06-14 15:35:53 +0200
committerGitHub <noreply@github.com>2023-06-14 15:35:53 +0200
commit2db09f27afed826507988569ce9ac60476d0c870 (patch)
treee63b42ffeae1e9e428acddf34fee91c98a7bb879 /share
parent6979d6a96f0f768c03cd7bc47e7ad1a82701a642 (diff)
downloadspack-2db09f27afed826507988569ce9ac60476d0c870.tar.gz
spack-2db09f27afed826507988569ce9ac60476d0c870.tar.bz2
spack-2db09f27afed826507988569ce9ac60476d0c870.tar.xz
spack-2db09f27afed826507988569ce9ac60476d0c870.zip
modules: use depends-on to autoload module with Lmod on Tcl (#38347)
Update Tcl modulefile template to use the `depends-on` command to autoload modules if Lmod is the current module tool. Autoloading modules with `module load` command in Tcl modulefile does not work well for Lmod at some extend. An attempt to unload then load designated module is performed each time such command is encountered. It may lead to a load storm that may not end correctly with large number of module dependencies. `depends-on` command should be used for Lmod instead of `module load`, as it checks if module is already loaded, and does not attempt to reload this module. Lua modulefile template already uses `depends_on` command to autoload dependencies. Thus it is already considered that to use Lmod with Spack, it must support `depends_on` command (version 7.6+). Environment Modules copes well with `module load` command to autoload dependencies (version 3.2+). `depends-on` command is supported starting version 5.1 (as an alias of `prereq-all` command) which was relased last year. This change introduces a test to determine if current module tool that evaluates modulefile is Lmod. If so, autoload dependencies are defined with `depends-on` command. Otherwise `module load` command is used. Test is based on `LMOD_VERSION_MAJOR` environment variable, which is set by Lmod starting version 5.1. Fixes #36764
Diffstat (limited to 'share')
-rw-r--r--share/spack/templates/modules/modulefile.tcl10
1 files changed, 9 insertions, 1 deletions
diff --git a/share/spack/templates/modules/modulefile.tcl b/share/spack/templates/modules/modulefile.tcl
index 577c40e47c..52d987da61 100644
--- a/share/spack/templates/modules/modulefile.tcl
+++ b/share/spack/templates/modules/modulefile.tcl
@@ -26,9 +26,17 @@ proc ModulesHelp { } {
{% endblock %}
{% block autoloads %}
+{% if autoload|length > 0 %}
+if {![info exists ::env(LMOD_VERSION_MAJOR)]} {
{% for module in autoload %}
-module load {{ module }}
+ module load {{ module }}
{% endfor %}
+} else {
+{% for module in autoload %}
+ depends-on {{ module }}
+{% endfor %}
+}
+{% endif %}
{% endblock %}
{# #}
{% block prerequisite %}