I have multiple bash script files named as run0.sh, run1.sh, run2.sh…runN.sh; which I want to run in parallel; instead of running each of them one-by-one. Also, Does assigning them into the no. of cores speed up the computation? How should I do that using the terminal?
You can run a process in the backgroud by adding an “&” at the end (e.g. ./run0.sh &) and starting them one after the other (./run0.sh &; ./run1.sh &; ./run2.sh &; ... etc), but for me, I’d run each in a separate terminal window, to better see any output from each one.
You can even do a script to open a terminal for each script. On XFCE, for instance:
#!/bin/bash
xfce4-terminal --hold -e "./run0.sh"
xfce4-terminal --hold -e "./run1.sh"
# and so on
I would leave a couple of threads (1 core?) free, though, just to keep some resources free so, if you have 8 cores (16 threads?), I’d run max 14 scripts at the same time; but it also depends on the available RAM and the speed of your storage (especially if you are reading/writing a lot, the storage may not keep up with the processor)…