#!/usr/bin/env zsh
 
### Job name
#BSUB -J MATLAB_PARPOOL
 
### File / path where STDOUT will be written, the %J is the job id
#BSUB -o MATLAB_PARPOOL.%J_%I
 
### Request the time you need for execution in minutes
### The format for the parameter is: [hour:]minute,
### that means for 80 minutes you could also use this: 1:20
#BSUB -W 800
 
### Request memory you need for your job in MB
#BSUB -M 12288

### Request the number of compute slots
#BSUB -n 12

### Use esub for OpenMP/shared memory jobs
#BSUB -a openmp
 
### Change to the work directory
cd $HOME/Documents/CinCChallange2017
 
### load modules and execute
module load MISC
module load matlab/2016b
 
# start non-interactive batch job
if [[ -z ${LSB_DJOB_NUMPROC} || ${LSB_DJOB_NUMPROC} -le 1 ]]; then
    # serial case ( with #BSUB -n 1 )
    matlabcmd="matlab -singleCompThread"
else
    # parallel, leave one CPU for system needs
    mytasks=${LSB_DJOB_NUMPROC}
    let mytasks-=1
    matlabcmd="taskset -c 0-$mytasks matlab"
fi
 
### open 'parpool' and run the 'dot-m-file.m' Matlab script in current directory
$matlabcmd c 27000@matlab.icts.maastrichtuniversity.nl -nodisplay -nodesktop -nosplash -logfile job.${LSB_JOBID}_${LSB_JOBINDEX}.txt <<EOF
parpool('local',str2num(getenv('LSB_DJOB_NUMPROC')))
% now run the 'dot-m-file.m' script
generateOverallModel
delete(gcp)
quit();
EOF

