0
  • I have a quad-core desktop computer
  • I have the Parallel Computing toolbox in Matlab.
  • I have a script file that I need to run simultaneously on each core

I'm not sure what the most efficient way to do this is, I know I can create a 'matlabpool' with 4 local workers, but how do I then assign the same script to each one? Or can I use the 'batch' command to run the script on a specific thread, then do that for each one?

Thank you!

2 Answers 2

1

You can run a single script using multiple cores using the Parallel Computing toolbox, by using matlabpool open local 4 and using parfor instead of for loops to execute whatever is in your loop across four threads. I'm not sure if Parallel Computing toolbox supports running the entirety of the script individually on each core, this will likely not be supported by your hardware.

Sign up to request clarification or add additional context in comments.

1 Comment

What about just calling batch('scriptname') 4 times, will it automatically spread them out on the different cores?
1

Not sure if this works, but here is something to try:

When trying to paralelize calculations, they are usually wrapped with something like parfor

So I would recommend doing the same with your script, make sure that all required inputs and outputs have the neccesary dimensions and just call:

parfor ii = 1:4
   myscript;
end

Sidenote: Before trying this kind of stuff you may want to check your cpu utilization. If it is already high that means that the inner part of the code uses parallel processing and you should not expect much speedup.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.