At IU, on Karst, how do I use MATLAB?

On Karst at Indiana University, you can use MATLAB interactively from the command line on the login nodes, or in batch mode using a TORQUE script to submit a job to the compute nodes. If your interactive session will require more than 20 minutes of processor time, you must run it on one of Karst's interactive nodes. You also can use the MATLAB graphical user interface (GUI) for interactive sessions by connecting to Karst using SSH with X forwarding enabled.

On this page:


Setting up your user environment

On the research computing resources at Indiana University, the Modules environment management system provides a convenient method for dynamically customizing your software environment.

To use MATLAB on Karst, you must first add the matlab module to your user environment. To make sure the matlab module is added every time you log into Karst, add the following line to your ~/.modules file:

  module load matlab

For more about using Modules to configure your user environment, see On the research computing systems at IU, how do I use Modules to manage my software environment?

Back to top

Submitting a MATLAB batch job

To submit a MATLAB batch job on Karst:

  1. Create an m-file (e.g., matlab_input.m) containing the commands MATLAB should run.
  2. Create a job script (e.g., matlab_job) for the TORQUE resource manager on Karst.

    For example (replace username with your IU username and username@iu.edu with your IU email address):

      #!/bin/bash
      #PBS -l nodes=1:ppn=16,walltime=1:00:00
      #PBS -M username@iu.edu
      #PBS -m abe 
      #PBS -N JobName
      #PBS -o matlab_output
      #PBS -e matlab_error
      
      cd /N/u/username/Karst/new_directory
      
      matlab < matlab_input.m

    The above example script will:

    • Request one hour of time for your job.
    • Change the working directory to the directory where the matlab_input.m m-file is located.
    • Have MATLAB run the commands in matlab_input.m.
    • Have Karst email you when the job is complete.
  3. Submit the script to TORQUE; from the command prompt, enter:
      qsub matlab_job
  4. To check the status of your job, use the qstat command (replace username with your IU username):
      qstat -u username

Running MATLAB interactively

You can run a short interactive MATLAB session from the command line on the login nodes; however, if your session will require more than 20 minutes of processor time, you must run an interactive job on a compute node.

  • To run a quick interactive session on a login node, load the matlab module, and then launch MATLAB from the command line; for example:
      [username@h2 ~]$ module load matlab
      [username@h2 ~]$ matlab
  • To run an interactive session on a compute node, first use the qsub command with the -I (interactive) option to submit a job request to Karst's interactive queue (-q interactive). When your job is ready and you are placed on a compute node, load the matlab module, and then launch MATLAB; for example:
      [username@h2 ~]$ qsub -I -q interactive -l nodes=1:ppn=1,walltime=1:00:00
      qsub: waiting for job 371037.m2 to start
      . . . 
      [username@c5 ~]$ module load matlab
      [username@c5 ~]$ matlab

Using the MATLAB GUI

To use the MATLAB graphical user interface (GUI), you must enable X forwarding in your SSH client's connection settings for Karst. Also, before connecting via SSH to Karst, you must have an X server program (e.g., Xming for Windows or XQuartz for OS X) running on your local computer. (For complete instructions, see On my personal computer, how do I use X forwarding to securely run graphical applications installed on IU's research computing systems?)

Once you have an SSH connection to Karst (with X forwarding enabled):

  • For a quick session, load the matlab module and launch MATLAB (as described in previous section).
  • For a session requiring more than 20 minutes of processor time, use qsub to submit a job request to Karst's interactive queue (as described in the previous section).

    Note: You must add the -X option to your qsub command to enable X forwarding.

    When your job is ready and you are placed on a compute node, load the matlab module, and then launch MATLAB; for example:

      [username@h2 ~]$ qsub -I -X -q interactive -l nodes=1:ppn=1,walltime=1:00:00
      qsub: waiting for job 371037.m2 to start
      . . .
      [username@c5 ~]$ module load matlab
      [username@c5 ~]$ matlab

Getting help

Support for IU research computing systems, software, and services is provided by various UITS Research Technologies units. For help, see Research computing support at IU.

Back to top

This is document ayfu in the Knowledge Base.
Last modified on 2015-05-22 00:00:00.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.