Submitting a Simple MATLAB Script

  • Let’s say that you want to run a script that creates a magic square and then saves that square matrix as a .mat file in your home directory on the cluster so that you can download it back onto your computer. Such a script and the .serial file needed to submit it are provided. The first step is to copy them to your folder (or a subfolder of your folder) on the cluster.
    1. The .serial file is what your ssh client uses to tell the cluster that it is submitting a job. It includes the queue to be used (-q), job name (-j), job overview name (-o), and error message name (-e). The latter two are saved to the folder that contained the .serial file.
    2. To submit the job, first make sure that on the ssh client your active folder is the one where you copied the files to. This is checked by typing “pwd”, which will tell you the active directory, and/or “ls”, which will tell you the contents of the active directory.
      1. When you first log in, you will be in /home/[username]/. To change to a subfolder of this directory, use the command “cd [foldername]”. If you want to go up a folder level (say you want to go from /home/[username] to /home), use the command “cd ../”.
    3. Check the .serial file from your ssh client by typing the command “more savemagic.serial”. Edit the matlab script with the command “vim magic_script.m” to change the save path. A vim commands list can be found here.
  • To submit the job, type the command “bsub < savemagic.serial” in the ssh client.
    1. Check that the job has been successfully submitted by typing the command “bjobs”.
    2. If it ran successfully, soon the file “magic_out_5.mat” should appear in the directory you chose, along with an output and an error message (hopefully an empty one) generated by the .serial file.
    3. Congratulations! You’ve run your first successful code on the cluster. The rest of the instructions will not have so many smaller details like this did, but it is important to understand all of the parts of the simple submission process.