Running the same matlab program in two matlab windows

52 views (last 30 days)
Hi,
Can I run the same matlab program in two different matlab workspaces with slight variations. For example in Matlab 1 workspace, if I put x =10 and run the program and in Matlab 2 workspace I put x =15 and run the same program, will it interfere with each others results. My programs are huge and time consuming, therefore I want to try this. I have a 4 core computer with huge RAM so I can open multiple workspaces.
Thanks, Nitin

Answers (4)

Jason Ross
Jason Ross on 2 Mar 2012
Generally, no.
Specifically, there are a few instances where running multiple MATLABs can affect each other:
  • If you attempt to write to the same file. For example, in your code you open "results.txt" in the same directory and both programs try and put their results there.
  • If you are dependent upon some shared resource that you assume exclusive access to -- generally this occurs when you are trying to access some piece of hardware that isn't designed to be shared. You can run into trouble there.
If you have access to the parallel computing toolbox, you can use the "local" scheduler on your machine to pretty much do what you describe, most likely using the spmd construct. You can open two MATLAB workers and send work to them. There are some restrictions on what you can do, but it's there if you want to look into it.

James Tursa
James Tursa on 2 Mar 2012
I do this all the time and it works just fine. However, pay attention to Jason's warnings. I don't write out to any files and I don't use any shared h/w resources etc.

rahi
rahi on 22 Mar 2012
On a related topic, does anyone know how the CPU times are affected if I run a simulation on two separate Matlabs or use parallel processing toolbox compared to the case that i use one simulation on one open maltab only. I need to find the CPU times of a series of simulations, I want to know if the CPU times get affected (and thus don't reflect the correct times) if I use parallel processing or more than one matlab. Plz help. Tnx.
  1 Comment
Jason Ross
Jason Ross on 26 Mar 2012
As I see it:
* Running two MATLABs, you are using twice the memory, sharing the CPU and possibly reading or writing from the same disk. Yes, there is a distinct possibility that things will be affected.
* Using PCT, you are opening some number of worker MATLABs. Same as the previous answer.
If you are benchmarking something, you should likely do the following:
* Boot the OS cleanly. Verify that things settle down by looking at machine load and RAM utilization.
* Start MATLAB, do your timings
* Run it again (to allow cache benefits to be realized)
If your simulation depends on an external resources like getting information from a database or from a network drive, I'd recommend multiple timings as more variables are introduced into your benchmark from network latency and server load. If possible, use local resources only.
Also, this should have been a new question since it's not truly the same question as the one above.

Sign in to comment.


Nitin
Nitin on 2 Mar 2012
Thanks guys. Let me try this using some simple programs and see if it works.

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!