Difference between revisions of "Cluster matlab"

From Biomedical Optics Lab
Jump to navigationJump to search
Line 45: Line 45:
 
</pre>
 
</pre>
  
This will move you from the head node to a node which can be used for computing.  That is, your terminal prompt will go from <code>[username@ada ~]</code> to <code>[username@node007 ~]</code>, for example.
+
This will move you from the head node to a node which can be used for computing.  That is, your terminal prompt will go from <code>[username@ada ~]</code> to <code>[username@node007 ~]</code>, for example. At the prompt, you can then start Matlab.
 +
 
 +
<pre>
 +
$ matlab -nodisplay -nodesktop
 +
</pre>
  
 
Note that not all nodes have Matlab installed.
 
Note that not all nodes have Matlab installed.
 +
 +
If you would like to use a graphical user interface (GUI), you must have X11 forwarding set up on your machine.  On a Windows computer, you can use MobaXTerm to connect to Ada and interact with Matlab as if it were on your computer.  We will update this page when we figure out how to do so on a Mac or within Visual Studio Code.

Revision as of 12:57, 25 June 2020

Using Matlab on the Cluster

We are exploring how to use Matlab with the new HPC cluster, and we will use this page to keep track of our current approaches.

Running Matlab Code As a Job Using Slurm

To properly use the cluster, we must submit jobs using the Slurm scheduler. To run an existing Matlab script, we just include its name in the Slurm instructions. Here is an example for running the Matlab code parforcluster.m. The text below could be named ada-submit and used for running all Matlab scripts by updating the filename inside the Matlab run command matlab -nodisplay -nosplash -nodesktop -r "run('./parforcluster.m');exit;". Note that until we have Matlab Parallel Server, we can only ever use one node at a time.

#!/usr/bin/env bash
# 
# submit batch file; based on CS 416 S20 ada-submit 

# Set SLURM options (you should not need to change these)
#SBATCH --job-name=testing                      # Job name
#SBATCH --output=./test-results/testing-%j.out  # Name for output log file (%j is job ID)
#SBATCH --nodes=1                               # Requesting 1 node and 1 task per node should
#SBATCH --ntasks-per-node=1                     # ensure exclusive access to the node
#SBATCH --cpus-per-task=32                      # Limit the job to only two cores
#SBATCH --partition=short                       # Partition (queue) 
#SBATCH --time=00:15:00                         # Time limit hrs:min:sec

# DONT MODIFY ANYTHING ABOVE THIS LINE

# Print SLURM envirionment variables
echo "# Job Info ----------------------------"
echo "Job ID: ${SLURM_JOB_ID}"
echo "Node: ${SLURMD_NODENAME}"
echo "Starting: "`date +"%D %T"`

echo -e "\n# Run Results -------------------------"
matlab -nodisplay -nosplash -nodesktop -r "run('./parforcluster.m');exit;"  # Run the Matlab script

# For reference, dump info about the processor
echo -e "\n# CPU Info ----------------------------"
lscpu

Running Matlab Interactively, Using Slurm to Assign the Node

For parallel computing, Matlab sets up a "parpool" of workers first to connect to the available CPUs. Unfortunately, if we execute the code using Slurm, our connection to the node will close, and the parpool session will end. That is, there will be an initialization time of ~15 seconds each time we send a Slurm job.

Instead, we would like to be able to keep out Matlab session open and work interactively within the assigned node. To have Slurm assign a node to use interactively, we can write:

srun --partition=long --pty --nodes=1 --ntasks-per-node=24 -t 00:30:00 --wait=0 --export=ALL /bin/bash

This will move you from the head node to a node which can be used for computing. That is, your terminal prompt will go from [username@ada ~] to [username@node007 ~], for example. At the prompt, you can then start Matlab.

$ matlab -nodisplay -nodesktop

Note that not all nodes have Matlab installed.

If you would like to use a graphical user interface (GUI), you must have X11 forwarding set up on your machine. On a Windows computer, you can use MobaXTerm to connect to Ada and interact with Matlab as if it were on your computer. We will update this page when we figure out how to do so on a Mac or within Visual Studio Code.