Search code examples
environment-modules

Is loading/unloading of environment modules commutative / associative?


I'm using environment modules: http://modules.sourceforge.net/

Are the load/unload commands commutative and associative? Or, is it possible that, e.g. if I do load X load Y The result will be different than if I do load Y followed by load X?

Can I view the "state" induced by these commands as just a list of which modules are loaded? Or does the order of these commands matter?


Solution

  • Modulefile loading order matters. Modulefiles X and Y may for instance alter the same environment variable by prepending or appending a path element to it.

    If modulefile X prepends /path/to/directoryX to PATH variable and modulefile Y prepends /path/to/directoryY to PATH, loading X then Y will give precedence to the binaries in /path/to/directoryY directory (as this directory will be the first element in PATH variable) over the binaries in /path/to/directoryX. When loading Y first then X, precedence will go the the binaries in /path/to/directoryX.

    If there is a binary named foo available in both directories, it will be found when invoked in the directory of the lastly loaded module in this example.

    To help users with such situation, modulefiles can express dependencies to ensure other modulefiles are loaded prior them (pre-requirement, prereq) or to ensure other modulefiles are not loaded if they are loaded (conflict).