I'm trying to run a python script in which part of the code is going to be parallelized according to some SLURM environment variables. I don't think the exact code is important, but for reference, I would like to use this to train my networks.
Now, the problem is that I need to run my script via srun, however this will spawn multiple parallel instances of my script which I don't want.
The most basic example would be this:
#!/bin/sh
#SBATCH -N 2
#SBATCH --ntasks=2
srun python myscript.py
Now I will have 2 nodes and 2 tasks, meaning that when I run python myscript.py there will be 2 instances of myscript.py running in parallel.
However, this is not what I want. I would like there to be only one instance of myscript.py running, however it should have access to the environment variables set by srun, and leave it to the python script to properly distribute the resources.
settings srun --ntasks=1 does not work, since then the script will only 'see' one of the nodes.
Is it possible to use srun to run a single instance of the script while it still has 'access' to the SLURM environment variables? I've looked at options such as --exclusive and --preserve-env, but they do not seem to help me in this case.