Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module switch while maintaing order #481

Closed
servesh opened this issue Dec 9, 2022 · 4 comments
Closed

Module switch while maintaing order #481

servesh opened this issue Dec 9, 2022 · 4 comments

Comments

@servesh
Copy link

servesh commented Dec 9, 2022

When one swaps modules, it would be helpful if there was a way to replace the relevant paths of the particular module is replaced in place maintaining path order.

module load foo/0.1
LD_LIBRARY_PATH=/opt/bar/0.1/lib:/opt/foo/0.1/lib:/opt/baz/0.1/lib

module switch foo/0.1 foo/0.2
does this,
LD_LIBRARY_PATH=:/opt/foo/0.2/lib:/opt/bar/0.1/lib:/opt/baz/0.1/lib

instead of
LD_LIBRARY_PATH=/opt/bar/0.1/lib:/opt/foo/0.2/lib:/opt/baz/0.1/lib

Any thoughts on how this can be supported?

@xdelaruelle
Copy link
Member

Due to the dependency management mechanisms replacing in-place is a hard task.

I see two leads here:

  • using dependency mechanism (prereq/module load) to ensure swapped-on module is at the correct index in path variables like LD_LIBRARY_PATH
  • using priority weight on path entries to set new path at an expected position

This second solution requires a feature addition, described in #185. I can work on this for next version if there is any interest.

@servesh
Copy link
Author

servesh commented Dec 13, 2022

Priority path would be useful for a different scenario, where you would want to ensure a specific module to be always placed first in the path.

I'm inclined to the first solution being closer to what I was hoping to achieve. When the old paths are removed from env variable, the index position is saved and used as the location to swap in the paths from the new module.

Could you suggest a sample or a template on how I can test this out?

@xdelaruelle
Copy link
Member

Some example based on your description of bar, baz and foo setting LD_LIBRARY_PATH:

$ cat bar/0.1
#%Module
prereq foo
prepend-path LD_LIBRARY_PATH /opt/[module-info name]/lib
$ cat foo/0.1
#%Module
prereq baz
prepend-path LD_LIBRARY_PATH /opt/[module-info name]/lib
$ cat foo/0.2
#%Module
prereq baz
prepend-path LD_LIBRARY_PATH /opt/[module-info name]/lib
$ cat baz/0.1
#%Module
prepend-path LD_LIBRARY_PATH /opt/[module-info name]/lib
$ module load bar
Loading bar/0.1
  Loading requirement: baz/0.1 foo/0.2
$ echo $LD_LIBRARY_PATH
/opt/bar/0.1/lib:/opt/foo/0.2/lib:/opt/baz/0.1/lib
$ module switch foo/0.2 foo/0.1
Switching from foo/0.2 to foo/0.1
  Unloading dependent: bar/0.1
  Unloading useless requirement: baz/0.1
  Loading requirement: baz/0.1
  Reloading dependent: bar/0.1
$ echo $LD_LIBRARY_PATH
/opt/bar/0.1/lib:/opt/foo/0.1/lib:/opt/baz/0.1/lib
$ module list
Currently Loaded Modulefiles:
 1) baz/0.1   2) foo/0.1   3) bar/0.1

Dependency order can be reversed if path are added to LD_LIBRARY_PATH with append-path rather prepend-path.

See also optional requirements capabilities to be able to unload a module without unloading modules that depend on it.

@xdelaruelle
Copy link
Member

I am closing this issue since:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants