How to run to Matlab programs without parallel toolbox

Hi everyone, I want to run two independent Matlab programs on the same PC. I'd like also to make clear that parallel toolbox is not an option cause I have to run Comsol which is an external program that can be called from matlab and solves FEM.
I bit of more info, the flowchart looks like that;
1)preparing data for subproblem i using matlab and comsol commands (which require trivial memory)
2) solve the FEM using Comsol (this drives my 24GB RAM PC to its limits)
3)post-processing(time-consuming but not significant memory requirements).
What I want is to start two matlabs, lets say A and B, independently (I can do that) and run in parallel two different scenarios.
However I need to find a way to tell Matlab that when the A executes the step 2 the B should wait to finish the job and vice versa, otherwise the PC crashes (Note that I was able to do the same using simpler FEM models in step 2 that do not require so much memory and worked fine)
Do you think is there any way/trick to do so?

 Akzeptierte Antwort

Daniel Shub
Daniel Shub am 10 Aug. 2011

0 Stimmen

You can use a lock file. Whoever starts step 2 first should write a file called something like step2.lock. When that machine finishes step 2, it should delete the file. Then you just need to see if step2.lock exists.

1 Kommentar

You have to be careful how you create the lock file, and you have to be _very_ careful if the lock file is being created in a networked file system.
If A and B both look and see that no lock file exists, both will attempt to create it. If one is not careful enough, _both_ of them will be told the creation is successful, leading both of them to think they can go ahead.
There are particular combinations of attributes that one can use when creating files on Unix-type systems (that are not using networked file systems) that catch this race condition. Unfortunately MATLAB's fopen() is not exactly the same as POSIX.1's fopen() and makes no promises about this kind of behavior. (Also if I recall correctly, you have to use open() instead of fopen() to get the right combination.)
I seem to recall that there is a MATLAB File Exchange contribution to implement semaphores between different MATLAB processes.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Jason Ross
Jason Ross am 26 Sep. 2011

0 Stimmen

FWIW it looks like Comsol and MATLAB can work together. I don't know if it will solve your particular problem, but I just wanted to pass on the information:
Giorgos Kourakos
Giorgos Kourakos am 26 Sep. 2011

0 Stimmen

Thank you all for the answers, They were really helpful. What I did it was the following I created a simple txt file with the letter A printed in. I was running both matlabs lets say A and B simultaneously and before step 2 there was a while loop that checked what it was printed in the file and the corresponding Matlab proceeded to step 2, while the other matlab was waiting. At the end of the step 2 the file was overwritten and the other Matlab started running the step 2. Although this was a very crude and not optimized way for doing parallel computing it worked and I had my results on time
Thank you again

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by