Hi Todd,

On 10/02/14 23:13, Heywood, Todd wrote:
It works for me with modules 3.2.10 (but not 3.2.9).
That's very weird, I didn't expect that...

In the mean time, I've figured out what the deal is with the single quotes.
After discussing this on the Lmod mailing list, things became clear to me.

Below is a copy-paste of my explanation on the Lmod mailing list.
The single quotes approach works but is actually wrong, and there's a much cleaner way (i.e. not using is-loaded guards around dependency "module load"s).

Here's what's going on. The two following expression in Tcl are equivalent:

    is-loaded GCC/4.7.2
    is-loaded "GCC/4.7.2"

In the second case, the quotes are stripped off. However, this does not happen with single quotes:

    is-loaded 'GCC/4.7.2'

The consequence of this is that this always evaluates to False, whether the module is loaded or not (which is obviously wrong), since "is-loaded" is checking whether a module with the name " 'GCC/4.7.2' " exists (so the single quotes are effectively part of name of the module being searched for).

This also explains the 'recursive unloading' behavior we're suddenly getting.
Let me use the below as example, with line numbers:

1  if { ![is-loaded 'GCC/4.7.2'] } {
2       module load GCC/4.7.2
3  }

Since the condition used in line 1 will always evaluate to "not False" a.k.a. "True", the body of the if clause will always be used, no matter whether the GCC/4.7.2 module is loaded or not.

On "module load", this will trigger loading GCC/4.7.2 as a dependency; no surprises there (except for always loading the module).

On "module unload", line 2 will be translated to "module unload GCC/4.7.2", since on unload all statements in the module file are basically translated to their complement.

WIthout single-quotes, the "is-loaded GCC/4.7.2" will be True on "module unload" (because the GCC/4.7.2 will be loaded), so the condition in the if clause will be "not True" a.k.a. "False", so the body of the if clause is skipped. Hence, it won't be translated to "module unload", hence no recursive unloading.

So, basically using single-quote breaks things. Although the recursive unloading is a nice side-effect, we're effectively making the 'is-loaded' check useless since it will always return False.

Simply dropping the "if is-loaded" guard around the "module load <dependency>" will also have the effect of "recursive unloading", but will also always load dependency modules, whether they were loaded already or not.

I've looked into reloading modules that are already loaded, and certainly with environment modules 3.2.10 this is harmless (the statements in the module file are not re-executed). Lmod takes a different approach (it unloads and reloads the module), so things may be trickier there, but it should still work.


regards,

Kenneth

Thanks for the help!

Todd

From: Kenneth Hoste <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Date: Monday, February 10, 2014 at 11:26 AM
To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: Re: [easybuild] module unload for toolchains?

Hi Todd,

On 10/02/14 17:21, Heywood, Todd wrote:
Hi Kenneth,

Thanks. I am actually using an older release of modules (from our default/base 
installation):

Modules Release 3.2.9 2011-11-24  (Copyright GNU GPL v2 1991):

That should do it, I think. I only have 3.2.10 around to play around
with though...

Can you take a look at the example I send right after my mail below, and
maybe try with v3.2.10 to see if that makes any difference for you?


regards,

Kenneth



Todd


From: Kenneth Hoste 
<[email protected]<mailto:[email protected]><mailto:[email protected]>>
Reply-To: 
"[email protected]<mailto:[email protected]><mailto:[email protected]>" 
<[email protected]<mailto:[email protected]><mailto:[email protected]>>
Date: Monday, February 10, 2014 at 11:14 AM
To: "[email protected]<mailto:[email protected]><mailto:[email protected]>" 
<[email protected]<mailto:[email protected]><mailto:[email protected]>>
Subject: Re: [easybuild] module unload for toolchains?

Hi Todd,

On 10/02/14 16:56, Heywood, Todd wrote:
Hi Pablo,

I only just got to this now. I tried your change (line 157 of 
module_generator.py), and I also tried this:


                 "if { ![is-loaded %(mod_name)s] } {",

                 "    module load %(mod_name)s",

                 ā€œ} else {",

                 "    module unload %(mod_name)s",

                 ā€œ}

                 "",

I regenerated modulefiles via eb. Unfortunately, the first try had no effect 
for unloading, and the second resulted in not being able to unload or purge any 
modules.

I’m probably missing something fundamental.

I'm currently looking into fleshing out Pablo's PR a bit more to add a
configure option for the wrapping of module names in the is-loaded
conditional, which triggers 'recursive unloading'.

Are you saying that wrapping the module name in single quotes as shown
below does not trigger recursive unloading at your end?

        if { ![is-loaded %(mod_name)s]} {   # NO recursive unloading
vs
        if { ![is-loaded '%(mod_name)s']} {   # WITH recursive unloading

Which modules tool are you using (environment modules, Lmod, ...), and
which version?

Also: I agree with your amazement that simply wrapping the module name
in single quotes (note: double quotes don't work >_<) has such a 'major'
effect...
Has anyone been able to find a reference for that? Is this documented
somewhere?


regards,

Kenneth



Reply via email to