-
Notifications
You must be signed in to change notification settings - Fork 3
/
04.Bootstrap_Slurm.sh
executable file
·87 lines (65 loc) · 2.75 KB
/
04.Bootstrap_Slurm.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
# Give data file names as arguments for the entire script
# Set slurm log directory (make sure ~ is expanded)
slurm_log_dir=`echo ~/simulation_code_bin/_slurm_files/`
# Set number of cores to use
n_cores=8
# Specify the real memory required per node in MegaBytes.
mem_per_node=24000
# Maximum runtime in minutes
run_time=7200
# SLURM partitions
# https://rc.fas.harvard.edu/resources/running-jobs/#SLURM_partitions
partition="serial_requeue"
# Define a function with two arguments
RunScript() {
# Argument 1 is R script name
r_script=$1
# Argument 2 is data file name (invoke from the script directory)
data_file=$2
# Argument 3 is which part of data to work on
parti=$3
# generate a part string
parti_str=`printf "%0*d\n" 2 ${parti}`
# Generate slurm log file names (remove path)
slurm_out_txt=`echo ${data_file%\.*} | sed -e "s/.*\///g"`.${r_script%\.*}_${parti_str}.out.txt
slurm_err_txt=`echo ${data_file%\.*} | sed -e "s/.*\///g"`.${r_script%\.*}_${parti_str}.err.txt
# Generate script name
script_name=`echo ${data_file%\.*} | sed -e "s/.*\///g"`.${r_script%\.*}_${parti_str}.slurm
# This part creates the script
# This flushes the file if it exists
echo "#!/bin/bash" > ${script_name}
echo "#SBATCH -n "${n_cores}" # Number of cores requested" >> ${script_name}
echo "#SBATCH -N 1 # Ensure that all cores are on one machine" >> ${script_name}
echo "#SBATCH -t "${run_time}" # Runtime in minutes" >> ${script_name}
echo "#SBATCH -p "${partition}" # Partition to submit to" >> ${script_name}
echo "#SBATCH --mem="${mem_per_node}" # real memory required per node" >> ${script_name}
echo "#SBATCH -o "${slurm_log_dir}${slurm_out_txt}" # Standard out goes to this file" >> ${script_name}
echo "#SBATCH -e "${slurm_log_dir}${slurm_err_txt}" # Standard err goes to this file" >> ${script_name}
echo "# Load R" >> ${script_name}
echo "# module load R_packages/3.2.2-fasrc01" >> ${script_name}
echo "module load centos6/R-3.1.2" >> ${script_name}
echo "# Configure R local package directory AFTER R has been loaded" >> ${script_name}
echo "export R_LIBS_USER=$HOME/apps/R:$R_LIBS_USER" >> ${script_name}
echo "# Invoke simulation runner with file name" >> ${script_name}
echo "Rscript" ${r_script} ${data_file} ${parti} >> ${script_name}
# Show script
echo ""
echo "Running this script"
cat ${script_name}
echo ""
# This part runs the script (data file name is coded)
echo sbatch ${script_name}
sbatch ${script_name}
# This part removes the script
echo rm ${script_name}
rm ${script_name}
}
for file in $@
do
for i in {1..10}
do
# Run i-th part
RunScript Bootstrap.R ${file} ${i}
done
done