Skip to content

Commit d946dcb

Browse files
committed
Lmod support
Change the way modules are handled, since Lmod supports proper exit codes. Therefore use them and get rif of the tmpfile debacle.
1 parent 740bbcf commit d946dcb

4 files changed

Lines changed: 53 additions & 50 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ The following script options are available:
106106
| `-Q <ARG>` | Set a queueing system for which the submit script should be prepared, supported `pbs-gen`, `slurm-gen`, `bsub-gen`.
107107
| `-P <ARG>` | Account to project or account `<ARG>`, only slurm, LSF (bsub).
108108
| `-M` | Use pre-installed modules instead of path settings, also needs specified module(s).
109-
| `-l <ARG>` | Specify a module to be used, will also invoke `-M`, may be specified multiple times to create a list, `<ARG>=0` clears the list.
109+
| `-l <ARG>` | Specify a module to be used, will also invoke `-M`, may be specified multiple times to create a list, `<ARG>=purge` unloads all modules and `<ARG>=0` clears the list.
110110
| `-i` | Execute in interactive mode (default without configuration).
111111
| `-B <ARG>` | Set the absolute path to the executable `xtb` to `<ARG>`. The name of the program needs to be included.
112112
| `-C <ARG>` | Set the name of the program directly, e.g. to access a different executable like crest (if installed).

configure/configure.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ ask_modules ()
482482
# use_module_system="false"
483483
# warning "Switching the use of modules off."
484484
fi
485+
ask "Would you like to purge pre-loaded modules?"
486+
use_purge_modules=$(read_true_false)
487+
debug "use_purge_modules=$use_purge_modules"
485488
# Unsetting read in module
486489
unset use_module_items
487490
local module_index=0
@@ -773,15 +776,24 @@ print_settings ()
773776
echo "#"
774777
if [[ -z $use_module_system ]] ; then
775778
echo "# use_modules=\"true\""
779+
echo "#"
780+
echo "# Allow to start fresh by allowing modules to be purged:"
781+
echo "#"
782+
echo "# purge_modules=\"true\""
783+
echo "# purge_modules=\"false\""
776784
else
777785
echo " use_modules=\"$use_module_system\""
786+
echo "#"
787+
echo "# Allow to start fresh by allowing modules to be purged:"
788+
echo "#"
789+
echo "# purge_modules=\"$use_purge_modules\""
778790
fi
779791
echo "#"
780792
if (( ${#use_module_items[@]} == 0 )) ; then
781793
echo "# They need to be named, too. For example:"
782794
echo "#"
783-
echo "# load_modules[0]=\"CHEMISTRY\""
784-
echo "# load_modules[1]=\"xtb\""
795+
echo "# load_modules[0]=\"xtb\""
796+
echo "# load_modules[1]=\"CREST\""
785797
else
786798
echo "# Specified modules to be loaded:"
787799
echo "#"

runxtb.rc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@
8080
# use_modules="true"
8181
use_modules="false"
8282
#
83+
# Allow to start fresh by allowing modules to be purged:
84+
#
85+
# purge_modules="true"
86+
# purge_modules="false"
87+
#
8388
# They need to be named, too. For example (on CLAIX18):
8489
#
85-
# load_modules[0]="CHEMISTRY"
86-
# load_modules[1]="xtb"
90+
# load_modules[0]="xtb"
91+
# load_modules[1]="CREST"
8792

8893
## Set Walltime for non-interactive mode
8994
#

runxtb.sh

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ helpme ()
119119
display_howto ()
120120
{
121121
local show_howto="${1:-xtb}"
122-
if [[ "$use_modules" =~ ^[Tt][Rr]?[Uu]?[Ee]? ]] ; then
122+
if [[ "$use_modules" =~ ^[Tt]([Rr]([Uu]([Ee])?)?)?$ ]] ; then
123123
debug "Using modules."
124124
# Loading the modules should take care of everything except threads
125125
load_xtb_modules || fatal "Failed loading modules."
@@ -219,11 +219,6 @@ get_bindir ()
219219

220220
cleanup_and_quit ()
221221
{
222-
# Clean temporary files
223-
if [[ -e "$tmpfile" && -f "$tmpfile" ]] ; then
224-
debug "$(rm -vf "$tmpfile")"
225-
fi
226-
227222
# Say a nice 'Bye bye!'
228223
message "Runxtb ($version, $versiondate) wrapper script completed."
229224

@@ -375,32 +370,20 @@ load_xtb_modules ()
375370
# Fail if there are no modules given (don't make any assumptions).
376371
(( ${#load_modules[*]} == 0 )) && fatal "No modules to load."
377372
# Fail if the module command is not available.
378-
( command -v module &>> "$tmpfile" ) || fatal "Command 'module' not available."
379-
# Try to load the modules, but trap the output in the temporary file.
380-
# Exit if that fails (On RWTH cluster the exit status of modules is always 0).
381-
# The new Lmod module system throws errors when loading all modules sequentially in one
382-
# command, thus they are now loaded sequentially.
383-
# Also checks if on RWTH cluster as the intel toolchain as to be unloaded before the foss
384-
# toolchain can be loaded without throwing errors.
385-
if [[ $(uname -n) == *"rwth"* ]]; then
386-
module unload intel &>> "$tmpfile"
373+
( command -v module 2>&1 ) || fatal "Command 'module' not available."
374+
# Since commited to only supporting proper module systems, failing to load
375+
# a module will produce an exit status > 0. This will be trapped and the script
376+
# will exit. (On the rwth cluster it is 'Lmod' - good choice.)
377+
# To be on the safe side, there should be the option to purge modules.
378+
if [[ "$purge_modules" =~ ^[Tt]([Rr]([Uu]([Ee])?)?)?$ ]] ; then
379+
modules purge &> >(debug_trace) || fatal "Failed to purge modules."
387380
fi
388-
381+
# Load the modules sequentially:
382+
local mod
389383
for mod in "${load_modules[@]}" ; do
390-
module load "${mod}" &>> "$tmpfile" || fatal "Failed to load module."
384+
module load "${mod}" &> >(debug_trace) || fatal "Failed to load module '${mod}'."
391385
done
392-
# Remove colourcodes with sed:
393-
# https://www.commandlinefu.com/commands/view/12043/remove-color-special-escape-ansi-codes-from-text-with-sed
394-
sed -i 's,\x1B\[[0-9;]*[a-zA-Z],,g' "$tmpfile"
395-
# Check whether then modules were loaded ok
396-
local check_module
397-
if grep -q -E "[Ee][Rr][Rr][Oo][Rr]" "$tmpfile" ; then
398-
debug "Issues loading modules."
399-
debug "$(cat "$tmpfile")"
400-
return 1
401-
else
402-
debug "Modules loaded successfully."
403-
fi
386+
debug "Modules loaded successfully."
404387
}
405388

406389
#
@@ -566,7 +549,7 @@ write_submit_script ()
566549
# Calculate the correct use of memory, add some overhead
567550
local corrected_memory
568551
corrected_memory=$(( requested_numCPU * requested_memory + 100 ))
569-
552+
570553
# Header is different for the queueing systems
571554
if [[ "$queue" =~ [Pp][Bb][Ss] ]] ; then
572555
cat >&9 <<-EOF
@@ -647,20 +630,23 @@ write_submit_script ()
647630
EOF
648631

649632
# Use modules or path
650-
if [[ "$use_modules" =~ ^[Tt][Rr]?[Uu]?[Ee]? ]] ; then
633+
if [[ "$use_modules" =~ ^[Tt]([Rr]([Uu]([Ee])?)?)?$ ]] ; then
651634
(( ${#load_modules[*]} == 0 )) && fatal "No modules to load."
652635
cat >&9 <<-EOF
653636
# Loading the modules should take care of everything except threads
654637
# Export current (at the time of execution) MODULEPATH (to be safe, could be set in bashrc)
655638
export MODULEPATH="$MODULEPATH"
656639
EOF
640+
# Next isn't really necessary, purging should do the trick.
657641
if [[ "$queue" =~ [Rr][Ww][Tt][Hh] ]] ; then
658-
echo "module unload intel" >&9
642+
echo "module unload intel 2>&1" >&9
643+
fi
644+
if [[ "$purge_modules" =~ ^[Tt]([Rr]([Uu]([Ee])?)?)?$ ]] ; then
645+
echo "modules purge 2>&1" >&9
659646
fi
647+
local mod
660648
for mod in "${load_modules[@]}" ; do
661-
cat >&9 <<-EOF
662-
module load "${mod}"
663-
EOF
649+
echo "module load '${mod}' 2>&1" >&9
664650
done
665651

666652
# Redirect because otherwise it would go to the error output, which might be bad
@@ -723,13 +709,6 @@ operatingsystem=$(uname -o)
723709
architecture=$(uname -p)
724710
processortype=$(grep 'model name' /proc/cpuinfo|uniq|cut -d ':' -f 2)
725711

726-
# Find temporary directory for internal logs (or use null)
727-
if ! tmpfile="$( mktemp --tmpdir runxtb.err.XXXXXX 2> /dev/null )" ; then
728-
warning "Failed creating temporary file for error logging."
729-
tmpfile="/dev/null"
730-
fi
731-
debug "Writing errors to temporary file '$tmpfile'."
732-
733712
# Clean up in case of emergency
734713
trap cleanup_and_quit EXIT SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
735714

@@ -746,9 +725,10 @@ request_qsys="pbs-gen"
746725
qsys_project="default"
747726
exit_status=0
748727
use_modules="false"
728+
purge_modules="true"
749729
declare -a load_modules
750-
#load_modules[0]="CHEMISTRY"
751-
#load_modules[1]="xtb"
730+
#load_modules[0]="xtb"
731+
#load_modules[1]="crest"
752732
stay_quiet=0
753733
ignore_empty_commandline=false
754734

@@ -855,10 +835,16 @@ while getopts :p:m:w:o:sSQ:P:Ml:iB:C:qhHX options ; do
855835
#hlp May be specified multiple times to create a list.
856836
#hlp The modules need to be specified in the order they have to be loaded.
857837
#hlp If <ARG> is '0', then reset the list.
838+
#hlp If <ARG> is 'purge', all (by default) loaded modules will be unloaded,
839+
#hlp then the list will be reset.
840+
#hlp Please note that an empty list will cause the script to fail.
858841
#hlp (Can also be set in the rc.)
859842
l)
860843
use_modules="true"
861-
if [[ "$OPTARG" =~ ^[[:space:]]*([0]+)[[:space:]]?(.*)$ ]] ; then
844+
if [[ "$OPTARG" =~ ^[[:space:]]*[Pp][Uu][Rr][Gg][Ee][[:space:]]*$ ]] ; then
845+
purge_modules="true"
846+
unset load_modules
847+
elif [[ "$OPTARG" =~ ^[[:space:]]*([0]+)[[:space:]]?(.*)$ ]] ; then
862848
unset load_modules
863849
[[ -n "${BASH_REMATCH[2]}" ]] && load_modules+=( "${BASH_REMATCH[2]}" )
864850
else

0 commit comments

Comments
 (0)