Matlab

Automatic home directory remount

If you are planning to run long lasting simulations and close the SSH-session during the simulation, you should be aware that your home directory is unmounted after some time. This may cause problems writing output files. You can avoid this running the script from the /locData/ folder.

Matlab

current version 2017a

local installed on all clients. (default is teaching)

matlab
other versions

other versions are available (check with module avail).


module load matlab/[VERSION_YOU_WANT_TO_RUN]

Matlab Script Starter

The following script is useful for starting Matlab scripts on remote machines using SSH. It solves the following issues:

  • Matlab interpreting '&' as input file
  • Start script without file ending
  • Loosing matlabs output
  • Typing in the full command
Matlab script starter
#!/usr/bin/env bash
#
# This script starts a Matlab session in the background using the
# *.m - script given as first argument.
#
# Matlabs output is written to the file 'log.txt'.
#
# For handy usage (Just call 'mls <script>') add this line to your
# bash_alias:
#     alias mls="sh ~/.matlab/mlScriptStarter.sh"
#
 
# Check, if argument is given
if [ -z "$1" ]; then
    echo "At least one argument required. Syntax: ./startMatlab.sh INFILE"
    return 1
else
    INFILE="$1"
fi
 
# Remove the file ending
if [ "${INFILE##*.}" = "m" ]; then
    BASE="${INFILE%%.*}"
else
    BASE="$INFILE"
fi
 
# Start Matlab
# ------------
# Some matlab options (see 'matlab -help' for more):
#     -nojvm        Shut off all Java support by not starting the
#                   Java virtual machine. In particular the MATLAB
#                   desktop will not be started.
#
#     -nodesktop    Do not start the MATLAB desktop. Use the current
#                   terminal for commands. The Java virtual machine
#                   will be started.
#
#     -nodisplay    Do not display any X commands. The MATLAB
#                   desktop will not be started. However, unless
#                   -nojvm is also provided the Java virtual machine
#                   will be started.
#
#     -nosplash     Do not display the splash screen during startup.
#
# Bash commands:
#     >    Pipe output to file
#     &    Background job
 
matlab -nodisplay -nosplash -r "${BASE}" > log.txt &
 
return 0

Save the code for example to ~/.matlab/mlScriptStarter.sh and make it executable.

Compile Matlab to Binary

Compile your m.script and all m-scripts with functions you have included. Your StandaloneScript.m should not depend on parameters (can but complicated).

 mcc -mv -o NameOfExecutable StandaloneScript.m FunctionScript1.m Functionscript2.m ...

For running the Executable you have to show the way to the matlab runtime libraries:

export LD_LIBRARY_PATH=/usr/local/matlab/research/runtime/glnxa64:/usr/local/matlab/research/bin/glnxa64:/usr/local/matlab/research/sys/os/glnxa64

or respectively for the woody cluster:

export LD_LIBRARY_PATH=/apps/matlab/R2014a/runtime/glnxa64:/apps/matlab/R2014a/bin/glnxa64:/apps/matlab/R2014a/sys/os/glnxa64

Then you can call the Executalbe itself:

./NameOfExecutable [parameters]

The mcc compiler also creates a shell script run_NameOfExecutable.sh which you can use to run your new binary file. As Parameter it needs the path to the matlab environment.

./run_NameOfExecutable.sh /usr/local/matlab/research
Example
better Examples incl. Cluster

Includes description on how to run the compiled standalone programms on cluster with qsub http://www.bu.edu/tech/support/research/software-and-programming/common-languages/matlab/standalone/

Log In