|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -set -e |
4 | | - |
| 3 | +set -es |
5 | 4 | usage() { |
6 | | - echo "Usage: $0 [script.sh] [cpu|gpu] [--single (optional)]" |
| 5 | + echo "Usage: $0 [script.sh] [cpu|gpu] [single|double]" |
7 | 6 | } |
8 | 7 |
|
9 | 8 | if [ ! -z "$1" ]; then |
10 | | - sbatch_script_contents=`cat $1` |
| 9 | + script_path="$1" |
11 | 10 | else |
12 | 11 | usage |
13 | 12 | exit 1 |
14 | 13 | fi |
15 | 14 |
|
16 | | -sbatch_cpu_opts="\ |
17 | | -#SBATCH -p cpu-small # partition |
18 | | -#SBATCH --ntasks-per-node=24 # Number of cores per node required |
19 | | -#SBATCH --mem-per-cpu=2G # Memory per core\ |
20 | | -" |
21 | | - |
22 | | -sbatch_gpu_opts="\ |
23 | | -#SBATCH -C V100-16GB |
24 | | -#SBATCH -G2\ |
25 | | -" |
26 | | - |
27 | 15 | if [ "$2" == "cpu" ]; then |
28 | | - sbatch_device_opts="$sbatch_cpu_opts" |
| 16 | + sbatch_device_opts="#SBATCH -p cpu-small |
| 17 | +#SBATCH --ntasks-per-node=24 |
| 18 | +#SBATCH --mem-per-cpu=2G" |
29 | 19 | elif [ "$2" == "gpu" ]; then |
30 | | - sbatch_device_opts="$sbatch_gpu_opts" |
| 20 | + sbatch_device_opts="#SBATCH -C V100-16GB |
| 21 | +#SBATCH -G2" |
31 | 22 | else |
32 | 23 | usage |
33 | 24 | exit 1 |
34 | 25 | fi |
35 | 26 |
|
36 | | -single_flag="" |
37 | | -if [ "$3" == "--single" ]; then |
38 | | - single_flag="--single" |
| 27 | +if [ "$3" != "single" ] && [ "$3" != "double" ]; then |
| 28 | + usage |
| 29 | + exit 1 |
39 | 30 | fi |
40 | 31 |
|
41 | | -job_slug="`basename "$1" | sed 's/\.sh$//' | sed 's/[^a-zA-Z0-9]/-/g'`-$2" |
42 | | - |
43 | | -if [ "$single_flag" == "--single" ]; then |
44 | | - job_slug="${job_slug}-single" |
45 | | -fi |
| 32 | +job_device="$2" |
| 33 | +job_precision="$3" |
| 34 | +job_slug="$(basename "$1" | sed 's/\.sh$//' | sed 's/[^a-zA-Z0-9]/-/g')-$job_device-$job_precision" |
46 | 35 |
|
47 | 36 | sbatch <<EOT |
48 | 37 | #!/bin/bash |
49 | 38 | #SBATCH -Jshb-$job_slug # Job name |
50 | 39 | #SBATCH --account=gts-sbryngelson3 # Charge account |
51 | 40 | #SBATCH -N1 # Number of nodes required |
52 | 41 | $sbatch_device_opts |
53 | | -#SBATCH -t 02:00:00 # Duration of the job (Ex: 15 mins) |
| 42 | +#SBATCH -t 02:00:00 # Duration of the job |
54 | 43 | #SBATCH -q embers # QOS Name |
55 | | -#SBATCH -o $job_slug.out # Output file |
56 | | -#SBATCH -W # Wait for the job to finish |
| 44 | +#SBATCH -o $job_slug-$job_precision.out # Include precision in the log file |
| 45 | +#SBATCH -W # Do not exit until the submitted job terminates. |
57 | 46 |
|
58 | 47 | set -e |
59 | 48 | set -x |
60 | 49 |
|
61 | 50 | cd "\$SLURM_SUBMIT_DIR" |
62 | 51 | echo "Running in \$(pwd):" |
63 | 52 |
|
64 | | -job_slug="$job_slug" |
65 | | -job_device="$2" |
66 | | -single_flag="$single_flag" |
67 | | -
|
68 | | -. ./mfc.sh load -c p -m $2 |
69 | | -
|
70 | | -$sbatch_script_contents |
| 53 | +# Load necessary modules |
| 54 | +. ./mfc.sh load -c p -m \$job_device |
71 | 55 |
|
| 56 | +# Execute the script with arguments |
| 57 | +bash $script_path "\$job_device" "\$job_precision" |
72 | 58 | EOT |
| 59 | + |
0 commit comments