Use Slurm job array instead of multiple jobs

This commit is contained in:
Kris Lamoureux 2024-08-14 22:50:29 -04:00
parent 0a37272620
commit f1bd37b0d8
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
2 changed files with 15 additions and 12 deletions

View File

@ -50,20 +50,20 @@ By default, each node is allocated:
By default, this script searches for prime numbers from `1-10,000` and `10,001-20,000` By default, this script searches for prime numbers from `1-10,000` and `10,001-20,000`
You can adjust the range searched per node by providing an integer argument, e.g.: You can adjust the range searched per node by providing an integer argument, e.g.:
/vagrant/primes.sh 20000 /vagrant/primes.sh 20000
The script will then drop you into a `watch -n0.1 squeue` view so you can see The script will then drop you into a `watch -n0.1 squeue` view so you can see
each job computing on `nodes[3-4]`. You may `CTRL+c` out of this view, and the job computing on `nodes[3-4]`. You may `CTRL+c` out of this view, and
the jobs will continue in the background. The home directory for the `submit` the job will continue in the background. The home directory for the `submit`
user is in the shared `/vagrant` directory, so the results from each node are user is in the shared `/vagrant` directory, so the results from each node are
shared back to the login node. shared back to the login node.
4. View the resulting prime numbers found, check `ls` for exact filenames 4. View the resulting prime numbers found, check `ls` for exact filenames
less slurm-1.out less slurm-1_0.out
less slurm-2.out less slurm-2_1.out
### Configuration Tool ### Configuration Tool

View File

@ -24,7 +24,7 @@ RANGE=${1:-10000}
function find_primes() { function find_primes() {
local START="$1" local START="$1"
local END="$2" local END="$2"
echo "INFO: Job $SLURM_JOB_ID looking for prime numbers from $START to $END" echo "INFO: Job ${SLURM_ARRAY_JOB_ID}_${SLURM_ARRAY_TASK_ID} looking for prime numbers from $START to $END"
for ((i=START;i<=END;i++)); do for ((i=START;i<=END;i++)); do
if [ "$(factor "$i")" == "$i: $i" ]; then if [ "$(factor "$i")" == "$i: $i" ]; then
echo "$i" echo "$i"
@ -32,10 +32,13 @@ function find_primes() {
done done
} }
if [ -z "$SLURM_JOB_ID" ]; then if [ -z "$SLURM_ARRAY_JOB_ID" ]; then
sbatch -N1 --wrap="$0 1 $RANGE" sbatch -N1 -a0-1 "$0" "$RANGE"
sbatch -N1 --wrap="$0 $((RANGE + 1)) $((RANGE * 2))"
watch -n0.1 squeue watch -n0.1 squeue
else else
find_primes "$1" "$2" if [ "$SLURM_ARRAY_TASK_ID" -eq 0 ]; then
find_primes 1 "$RANGE"
else
find_primes $((RANGE + 1)) $((RANGE * 2))
fi
fi fi