MATLAB on Orca: Difference between revisions

From Fluids Wiki
Jump to navigation Jump to search
m (Post update on errors of this page)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
There are two ways to run MATLAB live on Sharcnet. The first is through orca's development nodes, and the second 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.
<span style="color:red">THIS PAGE IS OUT OF DATE!! SEE [[MATLAB on Graham]]</span>


=== Development Nodes ===
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.
==== Set-up ====
In any case, you must have a valid Matlab account and have set-up Matlab on sharcnet (see [[#Set-up|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
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.


:''/opt/sharcnet/local/matlab/R2014a/bin/matlab -nosplash -nodesktop''


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.
== Set-up ==
* add ''-r "oldpath=cd('/home/$USER'); matlabstartup; cd(oldpath)"'' at the end of the first line of uwmatlab so that you have
After following the [https://ece.uwaterloo.ca/~nnikvand/Coderep/Sharcnet%20Codes/uw_matlab.pdf directions] to get Matlab, a few modifications are necessary.
:''/opt/sharcnet/local/matlab/R2014a/bin/matlab -nosplash -nodesktop -r "oldpath=cd('/home/$USER'); matlabstartup; cd(oldpath)"''


* create matlabstartup.m in /home/$USER
*Remove the -nojvm and -singleCompThread arguments from the first line so that you are left with
If using SPINS, a good command to have in the start-up file is
:''/opt/sharcnet/local/matlab/R2014a/bin/matlab -nosplash -nodesktop''
::''addpath('/work/$USER/spins/matlab')''
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.


==== To run Matlab ====
* 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.


* log into orca with X-forwarding (''ssh -X orca.sharcnet.ca'')
== Interactively ==
* log into one of the four development nodes with X-forwarding (''ssh -X orca-dev1'')
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.
* run Matlab (''./uwmatlab'')


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
=== With X-forwarding ===


::''pdsh -w orc-dev[1-4] uptime | awk '{print $1,$NF}' | sort -n -k 2''
* 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>)


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 can put this in a bash script by creating the file '''freedevnode.sh''' containing
=== Without X-forwarding ===


{|
* log into orca without X-forwarding (<code>ssh 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 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.
#!/bin/bash
* run Matlab (<code>./uwmatlab</code>)
* 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)
echo
* scp figure to local machine
pdsh -w orc-dev[1-4] uptime | awk '{print $1,$NF}' | sort -n -k 2
echo
|}


=== Visualization Machines ===
== 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 a visualization machine with X-forwarding (''ssh -X viz2-uwaterloo.sharcnet.ca'')
<syntaxhighlight lang="bash">
:Only machines 2 and 3 have Matlab available.
#!/bin/bash
* run Matlab with ''/opt/sharcnet/testing/matlab/R2014a/bin/matlab''
# bash script for submitting a matlab job to the sharcnet queue
:It is suggested to put this command in a file in your home directory just like the uwmatlab file.


If your data is not in your home or work directory you can mount scratch from other clusters onto the workstation. For example, to mount your /scratch directory from orca you should execute
#### Options ####
QUEUE=kglamb
MPP=12g
RUNTIME=2h
DELAY=false
DELAY_FOR=9175185
NAME=diagnostics
SCRIPT=diagnostics.m


::''mkdir /scratch/$USER/orca''<br />
#### OTHER INFO ####
::''sshfs $USER@orca.sharcnet.ca:/scratch/$USER /scratch/$USER/orca''
DATE=`date +%Y-%m-%d_%H\h%M`
LOG_NAME="mat_${DATE}.log"


See [https://www.sharcnet.ca/help/index.php/Visualization_Workstations visualization workstations] for more information.
#### 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>

Latest revision as of 15:56, 5 March 2019

THIS PAGE IS OUT OF DATE!! SEE MATLAB on Graham

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