Running the same MATLAB version twice and simultaneous and in the same computer.

Hello.
I want to run the same MATLAB version twice and simultaneous and in the same computer.
While one is performing a long time data processing the other is doing faster stuffs to test new ideas.
Some of these ideas are using the same m file used by the MATLAB performing long time data processing.
My question are:
Is it safe to change the files used by both MATLAB?
If a m file content is changed to test a new idea, the other MATLAB will update the file at the middle of the processing?
Thank you.
Best Regards,

Réponses (2)

An easy and safe way would be to duplicate the folder, which contains the M-files. If the path tree containing the user-defined folders is created dynamically this is easy and safe.
James Tursa
James Tursa le 8 Mar 2017
Modifié(e) : James Tursa le 8 Mar 2017
What do you mean by "safe"?
To run an m-file file, MATLAB first reads the file into memory (and parses it etc). Then the actual function that gets executed is this copy in memory. You do not have direct control over when this reading into memory takes place. E.g., suppose MATLAB "A" is running a loop and executing the m-file function fun.m within that loop. Then MATLAB "B" changes and saves a new copy of fun.m to disk. MATLAB "A" may still be running its memory copy of fun.m and not see the changes MATLAB "B" just made to this file because it isn't checking for fun.m file changes while it is executing the loop. If, however, you were to put a "clear fun" line immediately prior to calling fun within that loop, that would force MATLAB "A" to re-read into memory a new copy of fun each time it executed it, and that would force MATLAB "A" to see changes to fun.m that MATLAB "B" made. Or maybe it might cause MATLAB "A" to fail if MATLAB "B" has the file locked when MATLAB "A" tries to read it.
So, bottom line is you may have to put in specific code to force simultaneous MATLAB instances to behave as you want, but there may still be problems such as file locking etc that will cause things to fail. If you have a lot of function files this could be tedious of course. And it will slow down the processing as well since it takes extra time to re-read those function files every time you want to execute them.

1 commentaire

MATLAB does some checking to determine whether files on the user path have changed, but if I recall it only does that when it returns to the command prompt unless a rehash is specifically requested.
What happens if a file is changed while it is executing has varied over releases; it isn't always stable. Breakpoints into changed files can act pretty oddly.
Bottom line: even with a single MATLAB session, do not alter the code that is executing unless you specifically plain ahead for the changes.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by