MATLAB: Call multiple instances of another program from MATLAB

call program from matlabmultiplemultiple instancesParallel Computing Toolboxsystemthird party program

I'm writing a program that generates files to be simulated in a third party program. I would like to be able to call multiple instances of this third party program from within my MATLAB GUI.
I am able to call a single instance of the program using the "system" command, but MATLAB becomes busy until the simulation in the other program is complete. Sometimes the simulation can take several hours. I would like the ability to split up my input files into several smaller files and call multiple instances of this third party program from a single MATLAB program. Is it possible to call the "system" command without MATLAB becoming busy?
Is the Parallel Computing Toolbox required to do this?
Thank you, Miles

Best Answer

If you add the character '&' to the end of your system() command line, then system() will return as soon as the given program starts, without waiting for any output.
Depending on what you are doing, sometimes that is all you need -- to launch the commands and let them run.
Sometimes, though, you need to deal with the output of the program. If your system() command can tell the external program which output file to write into, sometimes you can check back to see if the file is ready. Doing that properly can be trickier than it sounds at first: you will not necessarily be able to just check if the output file exists, because the program might start writing to the file and might have it open for some time. There is no signalling mechanism for programs to say "Okay, I am finished with this file"; sometimes you can work something out with operating-system-specific "lock" facilities. Sometimes you can tell the readiness by the file size. Sometimes you might be willing to assume it is ready if it has not changed size in "sufficiently long". Sometimes you have to resort to checking to see which processes exist so you can tell whether the process exited.
If you are using MS Windows then there are ActiveX controls to create processes that you could use instead of system().
The Parallel Computing Toolbox has the benefit that you would not have to change anything about handling the external process other than making sure that any output files (and temporary files) have unique names so the copies do not clash with each other: you would system() up a particular invocation without using '&' and that worker would wait for that process to end.