-
Notifications
You must be signed in to change notification settings - Fork 0
/
fit_model.sh
executable file
·51 lines (40 loc) · 1.84 KB
/
fit_model.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
#!/bin/bash
[ $PBS_ARRAYID ] && TASK_ID=$PBS_ARRAYID
[ $SLURM_ARRAY_TASK_ID ] && TASK_ID=$SLURM_ARRAY_TASK_ID
[ $PBS_JOBID ] && JOBID=$PBS_JOBID
[ $SLURM_JOBID ] && JOBID=$SLURM_JOBID
JOBID=$(echo $JOBID | tr '[\[\]]' '_') #singularity doesn't like "[2]"
#singularity may fails to remove runtime directory (if cleanupd is killed by cluster)
#create /tmp sub directory for singularity to contain cachedir and remove it in epilogue
mkdir /tmp/$JOBID
export SINGULARITY_LOCALCACHEDIR=/tmp/$JOBID
#pull nth param sets using $SLURM_ARRAY_TASK_ID
params=$(head -$TASK_ID params.list | tail -1)
echo "Running TASK_ID:$TASK_ID $params ...................."
alpha_v=$(echo $params | cut -f1 -d" ")
alpha_f=$(echo $params | cut -f2 -d" ")
lambda_1=$(echo $params | cut -f3 -d" ")
lambda_2=$(echo $params | cut -f4 -d" ")
#might prevent parpool initialization error
#https://github.com/UCL-RITS/rcps-buildscripts/issues/55#issuecomment-256309931
#IT doesn't seems to work, and I've read that MATLAB_PREFDIR gets baked into the compiled module(?)
#https://undocumentedmatlab.com/blog/removing-user-preferences-from-deployed-apps
#export MATLAB_PREFDIR=/tmp/$SLURM_JOB_ID/pref
echo "TASK_ID=$TASK_ID running fit_model($alpha_v, $alpha_f, $lambda_1, $lambda_2)"
outpath="results/alpha_v_${alpha_v}_alpha_f_${alpha_f}_lambda_1_${lambda_1}_lambda_2_${lambda_2}.mat"
if [ -f $outpath ]; then
echo "output file already exist.. skipping"
exit 0
fi
echo "generating $outpath"
for i in $(seq 1 5);
do
echo "try $i of 5"
ls ./compiled
MAXMEM=16000000 singularity exec docker://brainlife/mcr:neurodebian1604-r2017a ./compiled/fit_model $alpha_v $alpha_f $lambda_1 $lambda_2 $outpath && break
echo "failed.. may retry"
sleep 15
done
#should be done by epilogue, right?? (what about slurm?)
#echo "removing tmp directory .. which should be empty by now"
#rmdir -rf /tmp/$JOBID