MATLAB on Orca: Difference between revisions

From Fluids Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
There is currently only a single way to run MATLAB live on Sharcnet through orca's development nodes. A second method that will soon be available is through the visualization machines. Before continuing you must have a valid Matlab account and have set-up Matlab on sharcnet ([https://ece.uwaterloo.ca/~nnikvand/Coderep/Sharcnet%20Codes/uw_matlab.pdf Directions]). As described in the directions link, Matlab scripts may also be submitted as jobs but this will not allow any interaction with the code.
There are two ways to run MATLAB on Sharcnet. The first is interactively through orca's development nodes, while the second is as a submitted job. Depending on how the first is used it could be impractical (see [[#Interactively|Interactively]]). The second is useful for running a time-consuming script like a diagnostic, or movie making function. Submitted jobs must be configured to run entirely on their own as there is no possibility of manually giving inputs.
In any case, you must have a valid Matlab account and have set-up Matlab on sharcnet (see [[#Set-up|Set-up]]).
 
Matlab can also be run on a local machine by remotely mounting Sharcnet. See [[Sharcnet_Tips#Remote Mount of Sharcnet|Remote Mount of Sharcnet]] on how to do this.
 
 
== Set-up ==
After following the [https://ece.uwaterloo.ca/~nnikvand/Coderep/Sharcnet%20Codes/uw_matlab.pdf directions] to get Matlab, a few modifications are necessary.


=== Development Nodes ===
==== Set-up ====
A few modifications need to be made to the uwmatlab file before running Matlab live.
*Remove the -nojvm and -singleCompThread arguments from the first line so that you are left with
*Remove the -nojvm and -singleCompThread arguments from the first line so that you are left with
:''/opt/sharcnet/local/matlab/R2014a/bin/matlab -nosplash -nodesktop''
* Add start-up commands
:That is enough to get Matlab working, but it is also a good idea to run a start-up file to add paths to your workspace and set defaults. Add these commands to <code>startup.m</code>, which must exist on the Matlab path (<code>/home/<USER>/Documents/MATLAB</code> should work). If using SPINS, a good command to have in the start-up file is:
::''addpath('/work/<USER>/spins/matlab')''
:or whatever the directory the Spins matlab files are in. This will allow you to use the built in Spins commands from any directory. Add other commands you want into this file as well (for example: maybe change the figure settings). This functionality will also apply to jobs submitted to the Sharcnet queue.
== Interactively ==
There are two ways to run Matlab interactively. Either with X-forwarding or without. The first can be slow for graphics, while the second removes graphic forwarding all-together. The second will probably be the most useful, since figures can be saved and then that file can be transferred to a local machine for viewing. Though this sounds like more work, it is actually faster.
=== With X-forwarding ===


:''/opt/sharcnet/local/matlab/R2014a/bin/matlab -nosplash -nodesktop''
* log into orca with X-forwarding (<code>ssh -X orca.sharcnet.ca</code> or using a configured ssh command - see [[ssh config]])
* log into one of the four development nodes with X-forwarding (<code>ssh -X orca-dev1</code> or <code>DevConnect</code> if the function has been declared). See [[Sharcnet Tips#Accessing Development Nodes|Accessing Development Nodes]] for info on <code>DevConnect</code> which will automatically choose the dev node with the lowest usage. For this reason it should be used over the generic ssh command.
* run Matlab (<code>./uwmatlab</code>)


That is enough to get Matlab working, but it is also a good idea to run a start-up folder to add paths to your workspace when you open Matlab.
=== Without X-forwarding ===
* add ''-r "oldpath=cd('/home/$USER'); matlabstartup; cd(oldpath)"'' at the end of the first line of uwmatlab so that you have
:''/opt/sharcnet/local/matlab/R2014a/bin/matlab -nosplash -nodesktop -r "oldpath=cd('/home/$USER'); matlabstartup; cd(oldpath)"''


* create matlabstartup.m in /home/$USER
* log into orca without X-forwarding (<code>ssh orca.sharcnet.ca</code> or using a configured ssh command - see [[ssh config]])
If using SPINS, a good command to have in the start-up file is
* log into one of the four development nodes with X-forwarding (<code>ssh orca-dev1</code> or <code>DevConnect</code> if the function has been declared). See [[Sharcnet Tips#Accessing Development Nodes|Accessing Development Nodes]] for info on <code>DevConnect</code> which will automatically choose the dev node with the lowest usage. For this reason it should be used over the generic ssh command.
::''addpath('/work/$USER/spins/matlab')''
* run Matlab (<code>./uwmatlab</code>)
or whatever directory the Spins matlab files are in. This will allow you to use the built in SPINS commands from any directory. This functionality will also apply to jobs submitted to the Sharcnet queue.
* print figure (the commands <code>print_figure</code> or <code>print_all</code> are built into the [https://github.com/ddeepwel/SPINSmatlab.git SPINSmatlab] package)
* scp figure to local machine


==== To run Matlab ====
== Submitted Job ==
Use the following script to submit a job (it is like the [[Sharcnet Tips#A script to handle this for you|submission script]] for a regular job, but built for matlab). You will need to replace <code><USER></code> with your user ID, or replace that line with the location of the matlab run file. This script can be told to wait for another submitted job to complete before running - just use the DELAY option. SCRIPT will specify which matlab file will be run.


* log into orca with X-forwarding (''ssh -X orca.sharcnet.ca'')
<syntaxhighlight lang="bash">
* log into one of the four development nodes with X-forwarding (''ssh -X orca-dev1'')
#!/bin/bash
* run Matlab (''./uwmatlab'')
# bash script for submitting a matlab job to the sharcnet queue


Some of the development nodes can get quite busy so it is a good idea to check the usage before logging in. One way to do this is to use the command
#### Options ####
QUEUE=kglamb
MPP=12g
RUNTIME=2h
DELAY=false
DELAY_FOR=9175185
NAME=diagnostics
SCRIPT=diagnostics.m


::''pdsh -w orc-dev[1-4] uptime | awk '{print $1,$NF}' | sort -n -k 2''
#### OTHER INFO ####
DATE=`date +%Y-%m-%d_%H\h%M`
LOG_NAME="mat_${DATE}.log"


which shows the number of processors being used on each node over the last 15 minutes. A value less than 4 will allow commands in Matlab to run at a reasasonable pace, anything over 10 is unbearably slow. See [https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB8QFjAA&url=https%3A%2F%2Fwww.sharcnet.ca%2Fhelp%2Findex.php%2FOrca&ei=uR8PVNPdHceKsQS3yIKoDQ&usg=AFQjCNHr8JWbktLeKZF6YNe3KO6F_7LN6Q&bvm=bv.74649129,d.cWc Documentation] for more information. Instead of typing this in at every login, you should make an alias.
#### Submit ####
if [[ -f ${SCRIPT} ]]; then
    if [[ "${DELAY}" = false ]]; then
        sqsub -q ${QUEUE} \
              --mpp=${MPP} \
              -r ${RUNTIME} \
              -j ${NAME} \
              -o ${LOG_NAME} \
              -i ${SCRIPT} \
              /home/<USER>/uwmatlab
    elif [[ "${DELAY}" = true ]]; then
        sqsub -q ${QUEUE} \
              --mpp=${MPP} \
              -r ${RUNTIME} \
              -j ${NAME} \
              -o ${LOG_NAME} \
              -w ${DELAY_FOR} \
              -i ${SCRIPT} \
              /home/<USER>/uwmatlab
    fi
    echo "Submitted ${SCRIPT} for matlab."
    echo "          Requested memory: ${MPP}"
    echo "          Requested runtime: ${RUNTIME}"
    echo "          Log file: ${LOG_NAME}"
else
    echo "Couldn't find ${SCRIPT} - Try again."
fi
</syntaxhighlight>

Revision as of 15:57, 20 March 2017

There are two ways to run MATLAB on Sharcnet. The first is interactively through orca's development nodes, while the second is as a submitted job. Depending on how the first is used it could be impractical (see Interactively). The second is useful for running a time-consuming script like a diagnostic, or movie making function. Submitted jobs must be configured to run entirely on their own as there is no possibility of manually giving inputs. In any case, you must have a valid Matlab account and have set-up Matlab on sharcnet (see Set-up).

Matlab can also be run on a local machine by remotely mounting Sharcnet. See Remote Mount of Sharcnet on how to do this.


Set-up

After following the directions to get Matlab, a few modifications are necessary.

  • Remove the -nojvm and -singleCompThread arguments from the first line so that you are left with
/opt/sharcnet/local/matlab/R2014a/bin/matlab -nosplash -nodesktop
  • Add start-up commands
That is enough to get Matlab working, but it is also a good idea to run a start-up file to add paths to your workspace and set defaults. Add these commands to startup.m, which must exist on the Matlab path (/home/<USER>/Documents/MATLAB should work). If using SPINS, a good command to have in the start-up file is:
addpath('/work/<USER>/spins/matlab')
or whatever the directory the Spins matlab files are in. This will allow you to use the built in Spins commands from any directory. Add other commands you want into this file as well (for example: maybe change the figure settings). This functionality will also apply to jobs submitted to the Sharcnet queue.

Interactively

There are two ways to run Matlab interactively. Either with X-forwarding or without. The first can be slow for graphics, while the second removes graphic forwarding all-together. The second will probably be the most useful, since figures can be saved and then that file can be transferred to a local machine for viewing. Though this sounds like more work, it is actually faster.

With X-forwarding

  • log into orca with X-forwarding (ssh -X orca.sharcnet.ca or using a configured ssh command - see ssh config)
  • log into one of the four development nodes with X-forwarding (ssh -X orca-dev1 or DevConnect if the function has been declared). See Accessing Development Nodes for info on DevConnect which will automatically choose the dev node with the lowest usage. For this reason it should be used over the generic ssh command.
  • run Matlab (./uwmatlab)

Without X-forwarding

  • log into orca without X-forwarding (ssh orca.sharcnet.ca or using a configured ssh command - see ssh config)
  • log into one of the four development nodes with X-forwarding (ssh orca-dev1 or DevConnect if the function has been declared). See Accessing Development Nodes for info on DevConnect which will automatically choose the dev node with the lowest usage. For this reason it should be used over the generic ssh command.
  • run Matlab (./uwmatlab)
  • print figure (the commands print_figure or print_all are built into the SPINSmatlab package)
  • scp figure to local machine

Submitted Job

Use the following script to submit a job (it is like the submission script for a regular job, but built for matlab). You will need to replace <USER> with your user ID, or replace that line with the location of the matlab run file. This script can be told to wait for another submitted job to complete before running - just use the DELAY option. SCRIPT will specify which matlab file will be run.

#!/bin/bash
# bash script for submitting a matlab job to the sharcnet queue

#### Options ####
QUEUE=kglamb
MPP=12g
RUNTIME=2h
DELAY=false
DELAY_FOR=9175185
NAME=diagnostics
SCRIPT=diagnostics.m

#### OTHER INFO ####
DATE=`date +%Y-%m-%d_%H\h%M`
LOG_NAME="mat_${DATE}.log"

#### Submit ####
if [[ -f ${SCRIPT} ]]; then
    if [[ "${DELAY}" = false ]]; then
        sqsub -q ${QUEUE} \
              --mpp=${MPP} \
              -r ${RUNTIME} \
              -j ${NAME} \
              -o ${LOG_NAME} \
              -i ${SCRIPT} \
              /home/<USER>/uwmatlab
    elif [[ "${DELAY}" = true ]]; then
        sqsub -q ${QUEUE} \
              --mpp=${MPP} \
              -r ${RUNTIME} \
              -j ${NAME} \
              -o ${LOG_NAME} \
              -w ${DELAY_FOR} \
              -i ${SCRIPT} \
              /home/<USER>/uwmatlab
    fi
    echo "Submitted ${SCRIPT} for matlab."
    echo "          Requested memory: ${MPP}" 
    echo "          Requested runtime: ${RUNTIME}"
    echo "          Log file: ${LOG_NAME}"
else
    echo "Couldn't find ${SCRIPT} - Try again."
fi