run_compiled_matlab_on_LISA.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #! /bin/bash
  2. # calls the compiled matlab file specified as first parameter, passing the second parameter, e.g.
  3. # example_script(5)
  4. #
  5. # PARAMETERS
  6. echo $1': matlab file name (e.g. "example_script", NOT example_script.m)'
  7. MATLAB_SCRIPT=$1
  8. echo $2': Job_nr'
  9. JOB_NR1=$2
  10. cd ..
  11. echo $3': Job_nr2'
  12. JOB_NR2=$3
  13. echo $4': Job_nr3'
  14. JOB_NR3=$4
  15. echo $5': Job_nr4'
  16. JOB_NR4=$5
  17. echo $6': Path to Logfile directory'
  18. LOGFILE_DIR=$6
  19. echo $7': Path to matlab file (e.g. /analysis/tom/example_dir/)'
  20. MATLAB_PATH=$7
  21. # check the number of arguments we need
  22. NARG=7
  23. if [ $# -ne $NARG ];then
  24. echo "ERROR: You must exactly provide $NARG arguments (see execute_matlab_process.sh for details)!" 1>&2
  25. exit 1
  26. fi
  27. # 2nd argument must be an integer
  28. echo $(( $JOB_NR1 + 1 )) >& /dev/null
  29. if [ $? -ne 0 ];then
  30. echo "ERROR: Second argument must be a job number (integer)!" 1>&2
  31. exit 1
  32. fi
  33. %
  34. LOC=`pwd`
  35. cd "$HOME" # ensure that you are in your home directory, to avoid matlab path problems (by default, the path information is saved in the home directory, so staring matlab from there uses the normal path of the user)
  36. HOSTNAME=`hostname`
  37. MYSELF=`whoami`
  38. DATE=`date`
  39. LOGFILE=$LOGFILE_DIR/log_job$JOB_NR1$JOB_NR2$JOB_NR3$JOB_NR4
  40. echo
  41. echo "Running job as $MYSELF on $HOSTNAME, $DATE" 2>&1
  42. echo
  43. # creating a new virtual screen using xvfb-run and calling then matlab, including a 'mini-program' to ensure all paths are added correctly
  44. # " , \ " at end of line is necessary, because this whole little program must be transmitted as one line to matlab.
  45. echo
  46. cd "$TMPDIR"
  47. cp $HOME/MVPA_Scripts/$MATLAB_SCRIPT "$TMPDIR" # Copy all scripts
  48. mkdir TMPResults
  49. mkdir TMPResults/TMPMatlab
  50. cp $HOME/TMPResults/TMPMatlab/$JOB_NR1"_"$JOB_NR3"_tmpfile.mat" "$TMPDIR"/TMPResults/TMPMatlab/
  51. #module load matlab
  52. #mcc -m "$TMPDIR"/MVPA_Scripts/$MATLAB_SCRIPT.m -a "$TMPDIR"/MVPA_Scripts/*.m
  53. #module unload matlab
  54. chmod +x $MATLAB_SCRIPT
  55. module load mcr
  56. ./$MATLAB_SCRIPT $JOB_NR1 $JOB_NR2 $JOB_NR3 $JOB_NR4
  57. module unload mcr
  58. # change back to the directory we came from
  59. cd $LOC
  60. echo
  61. echo "Job finished with Exit code $EXIT, returning"
  62. echo "Copy data from scratch back to home " 2>&1
  63. echo
  64. #cp -r "$TMPDIR"/TMPData/* $HOME/TMPData/
  65. cp -r "$TMPDIR"/TMPResults/* $HOME/TMPResults/
  66. if [ $EXIT -ne 0 ] ; then
  67. echo "WARNING: Job finished with error code $EXIT.
  68. Check the logfile why.
  69. If you have no clue why, and this happend the first time , just try to
  70. restart this job (copy the lines from to the terminal
  71. ../batch_dir/send_condor_all_jobs.sh). Dont call send_condor_all_jobs.sh
  72. again, because this will restart all jobs.
  73. If it crashs again, check if all machines are busy, and if so, wait a bit,
  74. and restart it again.
  75. If no normal logfile was created, the path to matlab that you provided
  76. might be wrong ($MATLAB_EXE). If this happens often, the target
  77. machine might be out of memory.
  78. If your jobs always crash on the same machine, copy & rename
  79. condor_generate_submit.sh and create your own version in which you exclude
  80. especially this machine (see condor_generate_submit_kai.sh as an example),
  81. then modify create_parallel.m to use this script.
  82. Job ran as $MYSELF on $HOSTNAME, $DATE" >> $LOGFILE.err
  83. fi
  84. # and finally return the exit status we got from xvfb
  85. exit $EXIT