Your Ad Here

Run MATLAB Jobs in the Background on a Mac or Linux Server

icon-matlab.gif Sometimes you don’t want to remain logged on or keep an ssh session open when running a MATLAB job. This guide will show you how to quickly create a script using nohup that will run MATLAB in the background, sending all output to a text file and even emailing you when the job is finished. Please note that this guide requires at least some use of the command line, so go ahead and open up the terminal.

Create the Script

Using VI, VIM, PICO, Emacs, or your favorite plain text editor create a new text file (e.g., runJob) containing the following:

#!/bin/csh
nohup matlab -nodisplay < YOUR_MATLAB_FILE.m > output.txt &

Now you will need to set the permissions on the file to allow execution by entering the following at the prompt.

chmod u+rwx runJob

When you type ./runJob and hit enter the MATLAB file (YOUR_MATLAB_FILE.m) will be executed with any output going to the output.txt file. Now you can log out of the machine and wait for the job to complete. However we can take this one step further by having the MATLAB file email you when the job has completed.

Have MATLAB Email You When Finished

Simply add the following line of code to the end of your MATLAB file

!pwd | mail -s finished YOUR_EMAIL_ADDRESS@GMAIL.COM

The ! calls the terminal sending an email with the subject ‘finished’ to YOUR_EMAIL_ADDRESS@GMAIL.COM and pwd places the directory of the job in the contents of the email. This way you know which job has completed as well as the server and location of the job.
Enjoy!





Have something to add? Send me a message on twitter or leave a comment below.

Viewing 4 Comments

 

Trackbacks

(Trackback URL)

close Reblog this comment
blog comments powered by Disqus

© Copyright Zaphu 2007. All rights reserved. -- Valid XHTML

Sitemap XML Sitemap XHTML