my workers will be running on the dual-core laptop machine where my Matlabpool using my default local configuration (i.e. This concept will become important when understanding why particular constraints are placed on the use of parfor.īefore looking at some examples, I will open up a matlabpool so I can run my loops in parallel. When MATLAB gets to the parfor-loop, it statically analyzes the body of the parfor-loop and determines what information goes to which worker and what variables will be returning to the client MATLAB. The cool thing about parfor is this data transfer is handled for the user. So, the data needed to do these calculations is sent from the client to workers,Īnd the results are sent back to the client and pieced together. However, when using a parfor-loop the iterations are run not on the client MATLAB machine but are run in parallel on MATLAB workers.Įach worker has its own unique workspace. In a parfor-loop (just like in a standard for-loop) a series of statements known as the loop body are iterated over a range of values. I have separated theseĮxamples into four encompassing categories: I decided to show a few examples highlighting the main challenges that one might encounter.
MATLAB FOR LOOP CODE
However, in other cases you may need to slightly alter the code so that parfor can work. In some cases, you may only need to change a for-loop to a parfor-loop to get their code running in parallel. Toolbox to the Parallel Computing Toolbox.
Note for clarity : Since Loren's introductory post, the toolbox used for parallel computing has changed names from the Distributed Computing There are also some nice introductory videos.
Loren has a very nice introduction to using parfor in one of her previous posts. I will assume that the reader has a basic knowledge of the Performance will not be addressed in this post. This post will focus on getting a parallel code using parfor up and running. The more commonly used functions in these tools: the parfor-loop. I wanted to write a post to help users better understand our parallel computing tools.