Robert Minsk wrote:
> Clever trick. But it is not quite what I wanted. I would rather
> have a module keep track of it's own reference count instead of
> each module referencing it to add a reference.
>
> I do not think it is currently possible within modules for a module
> to keep track of it's own reference count. The only way I think
> it would be possible is to add two new commands to modules to reference
> and unreference a module. The reference command would load a module if
> it was not already loaded otherwise add a reference to the currently
> loaded version. The unreference command would subtract a reference
> from the currently loaded version and if the reference count goes to 0
> remove it.
I like the idea of these commands; I had been thinking along
the lines of having 'require' do the job but this would then
eliminate the possibility of NOT loading the module if it isn't
already loaded (i.e., error out as now happens). Your solution
leaves the require functionality intact, doesn't break any
backwards compatability, and keeps the modulefiles clean.
Since state information is held in env vars, the easiest thing
to do would be to let modules define an obscure variable such
as "_LM_Synopsys_" for modulefile "Synopsys" (any version) and
increment/decrement that as necessary.
I had attempted to do this using Tcl before I hit upon the method
that you're now using, but in either case it was messy. I don't
particularly like needing to use "if" statements to "hide/unhide"
module load/unload commands inside another modulefile for this
reason. So I keep the modulefiles as simple as possible so the
rest of my team feels that modules and modulefiles are approachable.
Glad to hear that you found the method I posted useful.
Regards,
- Leo
|