forked from cdt-data-science/cluster-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onallnodes
executable file
·42 lines (34 loc) · 1.22 KB
/
onallnodes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
nodes=`sinfo --format="%N" --noheader`
partitions=`sinfo --format="%R" --noheader | tr '\n' ','`
print_usage () {
cat << EOM
Usage: $0 [-n nodelist] script
Runs given script on all nodes by submitting supplied script with sbatch.
Arguments:
script the script to be submitted to slurm via sbatch
-n (optional) specify nodes, either comma separated list, or summarised.
Mirrors slurm command -n usage in sinfo, and -w usage for squeue.
-p (optional) specify partitions, comma separated."
EOM
}
while getopts 'n:p:' flag; do
case "${flag}" in
n) nodes="${OPTARG}" ;;
p) partitions="${OPTARG}" ;;
*) print_usage
exit 1 ;;
esac
done
shift $((OPTIND-1))
script="${@}"
if [ "$script" = "" ]; then
>&2 echo "You must supply a script"
exit 1
fi
node_partition_list=`sinfo --format="%n,%R" --noheader -n ${nodes} -p ${partitions} -N`
nodes_filtered=`sinfo --format="%N" --noheader -n ${nodes} -p ${partitions}`
node=`echo "${node_partition_list}" | cut -f1 -d','`
partition=`echo "${node_partition_list}" | cut -f2 -d','`
echo "running $script on nodes $nodes_filtered"
parallel --link "sbatch --partition={1} --nodelist={2} ${script}" ::: $partition ::: $node