Is there a way to have run commands run one after the other under a single srun
? Additionally, can this be done without srunning a seperate file that has all the commands ?
Normally we would do :
srun python ./python_code.py
But I want :
srun python ./python_code1.py & python ./python_code2.py
Is this possible, or will it end up doing srun python ./python_code1.py
, then python ./python_code2.py
?
Alternatively, I can have a file that contains my list of executables, like this :
launch.sh:
python ./python_code_1.py
python ./python_code_2.py
which I would then call using srun launch.sh
.
But I want to do this all from a single file, if possible.
Thank,
Liam
A line such as
srun python ./python_code1.py & python ./python_code2.py
will start python ./python_code1.py
through srun
and send that process to the background, and immediately start python ./python_code2.py
.
As srun
is expecting an executable, you cannot directly list multiple commands as arguments. But it will forward the arguments of the command so you can use an intermediate invocation of bash
as suggested by @KamilKuk:
srun bash -c 'python ./python_code_1.py ; python ./python_code_2.py'
The alternative you mention with launch.sh
will work provided launch.sh
is executable, i.e. has the executable permission and has a proper Shebang.