Tool of the Week: Running Multiple Instances of Matlab on Mac

Notice There are two Matlabs Running!

My research often involves running Matlab Code that can take hours to run. Admittedly, Matlab isn't the fastest language out there, but it has super powerful debugging tools, and image processing packages that make it really easy to use for a non-computer scientist.

While matlab is running a bit of code, it won't let you do anything else, it just tells you it is "busy" at the bottom. Even editing other bits of code in the editor, as well as opening and saving files, can be sluggish to impossible while matlab is running. But I can't just sit around and wait while matlab is running, I've got graduating to do! On PCs, I remember running Multiple instances of matlab to be pretty straight forward. You could just click the matlab icon and a new instance would launch.

On Mac, it's not quite as easy. I find the best way to open a new instance is through the terminal. Go to Applications/Utilities/Terminal to launch the terminal (Or drag it to your Dock because it's a pretty useful tool!). When the command prompt is ready, simply enter in the command:

/Applications/Research/MATLAB_R2011b.app/bin/matlab

(NOTE: This might be different if your install of matlab is a different version or in a different location).

The terminal should launch another instance of Matlab (Note: if your matlab is installed in a different location, or is a newer version, you may need to edit this command). I like to keep the two instances of matlab, along with their editors, on separate desktops to keep them apart in my head. Note: Don't close the terminal window, because it is connected with this instance of matlab. If you'd like to open yet another instance, you'll need to open a new terminal window and repeat the command.

If you're running pretty intense code, it might do you good to run the activity monitor to watch your memory and cpu usage, as well as close other programs (even your web browser).

I almost always run matlab this way, because if it crashes or gets stuck and ctrl-c won't break it, i can exit it by closing the terminal!

Related Posts:

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.
  • DR

    Well, I remember working on Macs that would allow me to launch several instances of Matlab just by clicking on the Matlab icon on the Dock... and I currently work with Windows machines that only allow me to launch one Matlab session. I guess there must be some setting that controls that or maybe it depends on the kind of license, and it's not a platform-dependent problem.

    An improvement over your workaround: add this at the bottom of your .profile file (all in one line):

    alias run_matlab='screen /Applications/Research/MATLAB_R2011b.app/bin/matlab &'

    This has two advantages: first, you only have to type a short command (run_matlab) in the Terminal instead of a long string. Second, you can close the terminal window and even quit Terminal without killing your additional Matlab sessions.

  • Katerina Petrova

    Guys, thanx loads for that!!! I am doing Bayesian Estimation with Monte Carlo Markov Chains, using the Metropolis Hasting algo; which takes around 9 hours for each estimation(!!!) and I am doing it recursively, so I need to run it around 30 times!! , so you are life savers!!!

  • Katerina Petrova

    Is there any way I can open more than two Matlab windows?? I know it is possible on Windows, but can I do it on a Mac?

    • mrsoltys

      Katerina,
      Just repeat the same process to open as many matlab windows as you'd like. You'll need a new instance of the terminal for each instance of matlab.

      A warning, running more than 3 instances seems to make some computers a little unstable. You also might want to try using matlab's parfor function to speed up your code!

  • Katerina Petrova

    Thank you for your help.

    I can not use the parfor function, as I use a macroeconometric software that runs on top of Matlab, so the code is not actually in Matlab.

  • Fusiform

    I cannot thank you enough!!!! I was just about to buy the Parallel processing toolbox, and this does exactly what I need!!! I am analysing brain imaging data of 25 participants and batching them. With one instance they go 1:25, but now I open 5 instances can process 5 at a time. Thank you again, you have just increased my efficiency by 500%, my boss will be very happy 🙂

  • Fusiform

    On a related note, would you recommend getting the PCT anyway? Many thanks again

    • mrsoltys

      The parallel computing toolbox is is cool, but you must write your code a very specific way in order to have speed gains using it. If you don't feel like re-writing most of your code, and suffering some annoying errors, it sounds like running multiple instances will be fine for your needs.

      • Fusiform

        Thanks for your reply. I was hoping to use the 'batch' function where as far as I can understand you can run a script. I would have 5-6 versions of the script for each group participants (eg 5 participants per script). Do you think that would work? Am I understanding the 'batch' function correctly? Thanks again

  • Mariam

    Does many instances of Matlab can cause erroneous result. Is it possible that it may pick wrong data and overwrite data from one instance to another or its completely independent of each other?

    • If your variables are stored in RAM, they should be independent; however, if you're reading and writing from a data file on hard storage: running multiple instances most likely result in unexpected results