-
Notifications
You must be signed in to change notification settings - Fork 3
/
02.RunSimulation_Lsf.sh
executable file
·82 lines (59 loc) · 2.54 KB
/
02.RunSimulation_Lsf.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
#!/bin/sh
# Give data file names as arguments for the entire script
# Run in the script directory
# Set lsf log directory (make sure ~ is expanded)
lsf_log_dir=`echo ~/simulation_code_bin/_lsf_files/`
# Set number of cores to use
n_cores=4
# Set maximum time
max_time="06:00"
# Set Orchestra queue to use
queue="mcore"
# Define a function with two arguments
RunScript() {
# Argument 1 is data file name (invoke from the script directory)
data_file=$1
# Argument 2 is R script name
r_script=$2
# Generate lsf log file names (remove path)
lsf_out_txt=`echo ${data_file%\.*} | sed -e "s/.*\///g"`.${r_script%\.*}.out.txt
lsf_err_txt=`echo ${data_file%\.*} | sed -e "s/.*\///g"`.${r_script%\.*}.err.txt
# Generate script name
script_name=`echo ${data_file%\.*} | sed -e "s/.*\///g"`.${r_script%\.*}.lsf
# This part creates the script
# This flushes the file if it exists
echo "#!/bin/bash" > ${script_name}
echo "#BSUB -n "${n_cores}" # Number of cores requested" >> ${script_name}
echo "#BSUB -W "${max_time}" # Job maximum execution time" >> ${script_name}
echo "#BSUB -J "${script_name}" # Job name" >> ${script_name}
echo "#BSUB -o "${lsf_log_dir}${lsf_out_txt}" # Standard out goes to this file" >> ${script_name}
echo "#BSUB -e "${lsf_log_dir}${lsf_err_txt}" # Standard err goes to this file" >> ${script_name}
# https://wiki.med.harvard.edu/Orchestra/ChoosingAQueue
# The mcore queue has higher priority than the short or long queues,
# and jobs in it can't be suspended
echo "#BSUB -q "${queue}" # Submit to this queue" >> ${script_name}
# Do not e-mail. Too many messages.
# echo "#BSUB -N # Also e-mail to the address specified in ~/.forward file" >> ${script_name}
echo "export OMP_NUM_THREADS="${n_cores} >> ${script_name}
echo "# Load R" >> ${script_name}
echo "module load stats/R/3.2.1" >> ${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} >> ${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}
bsub < ${script_name}
# This part removes the script
echo rm ${script_name}
rm ${script_name}
}
for file in $@
do
RunScript ${file} 02.RunSimulation.R
done