@@ -119,7 +119,7 @@ helpme ()
119119display_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
220220cleanup_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)
723709architecture=$( uname -p)
724710processortype=$( 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
734713trap cleanup_and_quit EXIT SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
735714
@@ -746,9 +725,10 @@ request_qsys="pbs-gen"
746725qsys_project=" default"
747726exit_status=0
748727use_modules=" false"
728+ purge_modules=" true"
749729declare -a load_modules
750- # load_modules[0]="CHEMISTRY "
751- # load_modules[1]="xtb "
730+ # load_modules[0]="xtb "
731+ # load_modules[1]="crest "
752732stay_quiet=0
753733ignore_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