cc_staff
284
edits
No edit summary |
(Added virtual env. creation on multiple nodes) |
||
Line 249: | Line 249: | ||
<!--T:43--> | <!--T:43--> | ||
Note that the above instructions require all of the packages you need to be available in the python wheels that we provide (see "Available wheels" below). If the wheel is not available in our wheelhouse, you can pre-download it (see "Pre-downloading packages" section below). If you think that the missing wheel should be included in our wheelhouse, please contact [[Technical support]] to make a request. | Note that the above instructions require all of the packages you need to be available in the python wheels that we provide (see "Available wheels" below). If the wheel is not available in our wheelhouse, you can pre-download it (see "Pre-downloading packages" section below). If you think that the missing wheel should be included in our wheelhouse, please contact [[Technical support]] to make a request. | ||
==== Creating virtual environments inside of your jobs (multi-nodes) ==== | |||
In order to run scripts accross multiple nodes, each nodes must have it own virtual environment activated. | |||
1. In your submission script, create the virtual environment on each allocated nodes : | |||
<syntaxhighlight lang="bash"> | |||
srun --ntasks $SLURM_NNODES --tasks-per-node=1 bash << EOF | |||
virtualenv --no-download $SLURM_TMPDIR/env | |||
source $SLURM_TMPDIR/env/bin/activate | |||
pip install --no-index --upgrade pip | |||
pip install --no-index -r requirements.txt | |||
EOF | |||
</syntaxhighlight> | |||
2. Activate the virtual environment on the main node | |||
<syntaxhighlight lang="bash">source $SLURM_TMPDIR/env/bin/activate;</syntaxhighlight> | |||
3. Use <tt>srun</tt> to run your script | |||
<syntaxhighlight lang="bash">srun python myscript.py;</syntaxhighlight> | |||
==== Example (multi-nodes) ==== | |||
{{File | |||
|name=submit-nnodes-venv.sh | |||
|lang="bash" | |||
|lines=yes | |||
|contents= | |||
#!/bin/bash | |||
#SBATCH --account=<your account> | |||
#SBATCH --time=00:30:00 | |||
#SBATCH --nodes=2 | |||
#SBATCH --ntasks=2 | |||
#SBATCH --mem-per-cpu=2000M | |||
module load StdEnv/2023 python/3.11 mpi4py | |||
# create the virtual environment on each node : | |||
srun --ntasks $SLURM_NNODES --tasks-per-node=1 bash << EOF | |||
virtualenv --no-download $SLURM_TMPDIR/env | |||
source $SLURM_TMPDIR/env/bin/activate | |||
pip install --no-index --upgrade pip | |||
pip install --no-index -r requirements.txt | |||
EOF | |||
# activate only on main node | |||
source $SLURM_TMPDIR/env/bin/activate; | |||
# srun exports the current env, which contains $VIRTUAL_ENV and $PATH variables | |||
srun python myscript-mpi.py; | |||
}} | |||
=== Available wheels === <!--T:23--> | === Available wheels === <!--T:23--> |