Default behaviour
All environment variables that are set in the shell at Job submission will be propagated to the sbatch script and will also be seen by commands run via srun . This includes for example:
- all env vars defined in your
~/.bashrc,.bash_profileand~/.profilethat are loaded when you log in interactively via SSH. - all env vars set either manually or via modules
- all env vars set by commands executed during or after login (e.g. anaconda/miniconda)
Avoid letting (ana|mini)conda write to your ~/.bashrc by invoking conda shell bash or similar. Always load via Lmod modules either before submitting Jobs or (preferred) in your sbatch script!
login or non-login shell, an interactive or non-interactive shell, and might be a remote shell or normal shell if SSH was involved in the execution or not. Depending on the type of shell, certain dotfiles (~/.bashrc , .bash_profile, ~/.profile ) are loaded or not.For example:
- When you login one of the login nodes via SSH, a
remote iteractive loginshell is invoked,.bash_profileand~/.profilewill be loaded, but~/.bashrcwill not. - When you submit a Jobscript via sbatch, the Slurm Step Daemon invokes a
normal non-login non-interactiveshell and no dotfile will be loaded (env vars may be interited from the submitting shell). - When you invoke an interactive shell (e.g. via
srun --time=1-0 --pty bash), anormal non-login interactiveshell is started, and just~/.bashrcis loaded.
Fortunately, there is a ~/.profile dotfile by default, which also loads ~/.bashrc if it exists. So in all cases where any file will be loaded, ~/.bashrc will be loaded as well!
The recommended way to define aliases, environement variables and functions is to use ~/.bashrc exclusively.
Clean environments
Slurm offers several ways to start with no environments at all or clean environments (state right after login) with two Sbatch options: --export and --get-user-env .
Environment best practises
~/.bashrc to modify your default environment!~/.profile !type <command> if this name is already taken.and most importantly
~/.bashrc minimal!