Matlab

      Comments Off on Matlab

Link explaining the ‘Campus License’

Description

MATLAB, an acronym for “MATrix LABoratory,” is a numerical computing and programming software developed by MathWorks. It is widely used in the fields of engineering, applied sciences, mathematics, and academic research to perform a variety of tasks, including data analysis, modeling, simulation, optimization, and visualization.

Set up the environment and version

ml apps/matlab
  • Available version(s) : R2024b
  • Enter your MathWorks credentials during the first matlab launch when prompted.

Warning

  • Running a calculation through an OpenOnDemand session on the visualization node or via an interactive job with default settings is NOT recommended
  • Only a single core of the machine will be allocated.
  • This could result in significantly slower computation times.

  • DO NOT launch MATLAB with the command: ‘ml apps/matlab; matlab’, as this will cause a licensing issue. Instead, run the two commands separately: first, ‘ml apps/matlab’, then ‘matlab’.

Quick Start

Matlab Graphical Session

  • Connect to OpenOnDemand
  • Open a terminal in your session
  • Type one of the following salloc commands:
# Choice 1 : Only CPU
salloc --nodes=1 --partition=normal --exclusive --mem-per-cpu=4G --time=1:00:00 --x11

# Choice 2 : Using GPU
salloc --nodes=1 --partition=bigpu --exclusive --gres=gpu:2 --mem-per-cpu=9G --time=1:00:00 --x11

# Choice 3 : Using FPGA
salloc --nodes=1 --partition=fpga --exclusive --gres=fpga:3 --mem-per-cpu=15G --time=1:00:00 --x11

# Adjust or complete your command according to your needs
  • Once you have obtained the node number, type the following commands:
ssh -X nodeYYY
# Replace nodeYYY with the node name where your job was launched
ml apps/matlab
matlab

Tutorials

Preamble – MATLAB Computation on MatriCS and MATLAB Parallel Server

To fully harness the computational power of MatriCS, we recommend using MATLAB Parallel Server. This tool, developed by MathWorks, enables large-scale parallel and distributed computations on clusters or high-performance computing (HPC) environments. MATLAB Parallel Server extends MATLAB’s computing capabilities beyond the local machine by distributing tasks across multiple nodes or processors, thus accelerating complex and resource-intensive operations.

However, it is common to run computations on a single machine without utilizing multiple nodes. The first tutorial covers the standard use of MATLAB, while the second guides you through using MATLAB Parallel Server after connecting to MatriCS.

Running a Matlab computation without using Matlab Parallel Server

Matlab can be launched in console mode, which runs without a graphical interface, making it ideal for quickly executing scripts in a terminal. In interactive mode, Matlab opens its full interface with graphical tools, which is useful for exploring data and developing algorithms.

Launching in console mode

  • Launch an interactive job without the --x11 option
# Launching an interactive job without GPU
srun --cpus-per-task=8 --mem-per-cpu=4G --time=1:00:00 --pty /bin/bash

# Launching an interactive job with 1 GPU
srun --partition=bigpu --gres=gpu:1 --time=1:00:00 --pty /bin/bash

# Launching an interactive job with 1 FPGA
srun --partition=fpga --gres=fpga:1 --time=1:00:00 --pty /bin/bash

# Adjust or complete the commands according to your requirements.
  • Launching the job may take a few minutes. Type squeue --me to check the status of your job. (To regain control and type the squeue command, press Ctrl+Z, then type bg to run it in the background. To return to your srun command, type fg).
  • Once connected to the node, launch MATLAB.
ml apps/matlab
matlab
  • If this is your first launch, your MathWorks credentials will be requested.
  • During the first launch, type the command pwd in the MATLAB command prompt to determine which directory you are in. This directory should be different from the one from which you launched MATLAB.
  • Navigate through the directories using the cd command.
  • Display the contents of the directories using the ls command.
  • Exit MATLAB with the quit command.

Launching in interactive mode

If this is your first time launching Matlab on MatriCS, please start it in console mode first in order to configure your profile.

  • Connect via SSH using the -X option
ssh -X mylogin@login.matrics.u-picardie.fr

For macOS users, create a java.opts file at the root of your MatriCS account with the following lines (for example, nano ~/java.opts).

-Dsun.java2d.xrender=false
-Dsun.java2d.pmoffscreen=false

This will prevent the background of the MATLAB interface from turning black when you move the mouse.

  • Launch an interactive job (using the --x11 option)
# Launching an interactive job without GPU
srun --cpus-per-task=8 --mem-per-cpu=4G --time=1:00:00 --pty --x11 /bin/bash

# Launching an interactive job with 1 GPU
srun --partition=bigpu --gres=gpu:1 --time=1:00:00 --pty --x11 /bin/bash

# Launching an interactive job with 1 FPGA
srun --partition=fpga --gres=fpga:1 --time=1:00:00 --pty --x11 /bin/bash

# Adjust or complete the commands according to your requirements.
  • Launching the job may take a few minutes. Type squeue --me to check the status of your job. (To regain control and type the squeue command, press Ctrl+Z, then type bg to run it in the background. To return to your srun command, type fg).
  • Once connected to the node, launch Matlab
ml apps/matlab
matlab

Useful MATLAB Commands

  • Number of cores: feature('numCores')
>> feature('numCores')
MATLAB detected: 64 physical cores.
MATLAB detected: 64 logical cores.
MATLAB was assigned: 8 logical cores by the OS.
MATLAB is using: 8 logical cores.
MATLAB is not using all logical cores because Operating System restricted the number of cores to: 8.

ans =
     8
  • The number of cores returned by feature('numCores') corresponds to the number X you specified with the option --cpus-per-task=X
  • Information about GPUs: gpuDevice()
>> gpuDeviceCount                
ans =
     2
>> gpuDevice(2)
ans = 
  CUDADevice with properties:
   Identity
                      Name: 'Tesla V100-PCIE-32GB'
...
                     Index: 2 (of 2)
  • The number of GPUs returned by gpuDeviceCount corresponds to the number Y of GPUs you specified with the option --gres=gpu:Y

Using Matlab Parallel Server

You can follow this tutorial either from your Matlab client or from MatriCS. In the latter case, go to the step titled ‘Launching Matlab from MatriCS’.

Configuring your Matlab client for MatriCS

To follow this tutorial with your Matlab client, it is necessary to have already configured it for MatriCS by executing the .p file. The procedure is described on this page.

If that is the case, you can go directly to the step titled ‘Launching a Job’.

Launching MATLAB from MatriCS

To follow this tutorial on MatriCS, you can launch an interactive session on the visualization node and open a terminal (Click on the second icon at the bottom – the black rectangle).

  • Type the command ml apps/matlab.
  • Then the command matlab.
ml apps/matlab
matlab
  • Eventually, enter your MathWorks credentials (this is only requested the first time you launch MATLAB)
  • If it proposes a new version of Matlab, click on “Do not show again.”

Launching a job (example: calculating pi with or without GPU)

  • If the tutorial ‘MATLAB Job Submission on MatriCS’ is not displayed, double-click the ‘MATLAB’ folder, then open the ‘ClusterExample’ folder, and finally click on ‘JobExample.mlx’.
  • The continuation of the tutorial for launching a job with MATLAB on MatriCS

If the job has completed successfully, you should see the estimated value of pi displayed, approximately 3.14.

results = 1x1 cell array
    {[3.1414]}

Some useful resources

Documentation