How to improve interactive performance of MATLAB

When using ssh X11-Forwarding (options -X or -Y), matlab can be slow to start and also have slow response to interactive use. This is because X11 sends many small packets over the network, often awaiting a response before continuing. This interacts unfavorably with medium or even higher latency connections, i.e. WiFi. When starting matlab on mistralpp nodes, another disturbing factor is overloading of these nodes.

But mistral has means to eliminate both of these issues: GPU nodes provide exclusive resources and allow for starting a remote desktop session that does not suffer from network latencies. Furthermore, the program execution can benefit from the hardware acceleration for 3D-plots or other graphics-intensive matlab sessions.

The steps to set this up are as follows:

  1. Reserve resources on a GPU node (if you know the number of CPUs or the amount of memory needed for your Matlab session provide the -n or –mem options or use the -N 1 option to reserve a node exclusively) and connect to it via ssh from one of the login nodes:

    mlogin100% salloc -n 1 --mem 32000 -p gpu -t 12:00:00 -A YOUR_PROJECT -- /bin/bash -c 'ssh -X $SLURM_JOB_NODELIST'
  2. Start a VNC server on the GPU node:

    mgXXX% /opt/TurboVNC/bin/vncserver -geometry 1680x1050 -localhost

    The argument of geometry should take a value that works well for your screen, see your desktop preferences for an appropriate value.

  3. The output will be something like

    Desktop 'TurboVNC: mg100:1 (k202069)' started on display mg100:1

    Notice the server, in this case mg100, and the display (:1).

  4. Open a second ssh connection from your local computer. Here we forward the port for vnc communication which is 5900 + display number. For the example above, it would be 5901.

    your-machine:~> ssh -L YYYY:localhost:YYYY

    Enter your specific host and port number for XXX and YYYY

  5. Start vncviewer on your local machine:

    your-machine:~> vncviewer localhost:DISPLAY

    DISPLAY must match what your session in 1. provided.

    If your local machine has Linux or Mac operating system you can use a launcher provided by DKRZ to easily establish a VNC connection to a GPU node. The launcher automatically connects to Mistral, reserves a GPU node, starts a vnc server and connects to this server using your local vncviewer. You need to complete the downloaded script start-vnc by adding your personal project and user numbers or to use the corresponding command line options:
    your-machine:~> chmod u+x start-vnc
    your-machine:~> ./start-vnc
    your-machine:~> ./start-vnc -u <userid> -A <prj_account>

    To list all available command line options execute:

    your-machine:~> ./start-vnc -h

    If you have not set a VNC server password yet, the vncpasswd command will be called in the script and you will be prompted to create a password:

    No VNC password found. Please set now.
    Would you like to enter a view-only password (y/n)? n
    The created password will be stored in $HOME/.vnc/passwd file. Since it only protects the VNC session, it should be different from your regular access password to DKRZ services. Also, since the password will only be used in automated logins afterwards and you don’t need to enter it on the console, it can be long and random at no cost.
    Furthermore, public key based login to MISTRAL is recommended to avoid multiple entering of your regular password.
  6. In the VNC desktop that should appear on your local workstation, open a terminal window via the Applications menu:

    Applications -> System Tools -> Terminal

  7. Load the matlab module in the terminal window and start matlab with vglrun and without software OpenGL:

    $ source /etc/profile.d/
    $ module load matlab
    $ vglrun matlab
    Note: It is necessary to start MATLAB in your HOME directory to avoid excessive warnings or error messages.

  8. To terminate your VNC session choose the Disconnect icon [x] in the top menu of the VNC desktop.