Monday, May 13, 2013

Speeding up MATLAB code using matlab distributed computing toolbox

MATLAB's distributed computing toolbox is a great tool to fully utilize your multi-core processors. If you have the distributed computing toolbox installed, the setup is quite easy. The steps to start parallel processing on your localhost are given below. To use a cluster of computers through the LAN, the setup is similar.

The steps given are for Windows 7, though the steps for linux are the same.
  1. First open a command prompt using "Run as Administrator"
  2. Go to %matlabroot% directory which is usually "C:\Program Files\MATLAB\R2011a"
  3. Now cd to "toolbox\distcomp\bin"
  4. Install the mdce service using "mdce install"
  5. run admincenter
  6. Add hosts (your computer is localhost)
  7. start mdce service
  8. start jobmanager
  9. start workers

Now open matlab go to "Parallel" menu. Manage Configurations and create a new job manager. 

In the properties, in the Jobs tab, job manager hostname should be "localhost". Job manager's name should be the name you used earlier. 

In the Jobs tab, input the minimum and maximum number of workers. The number of workers should be less than the number of processors in your computer. Click OK and you are done.

Now that the distributed computing toolbox is set up you can use the "matlabpool" command and the "parfor" loop to speed up code.

If the mdce service, the jobmanager and the workers keep running, the system gets slow. Therefore, to stop the workers, in the command prompt run :
%matlabroot%\toolbox\distcomp\bin\admincenter
Now stop the workers and the job manager. To stop the mdce service use the command :
mdce stop
Note that you must have the mdce service, the job manager and the workers running to be able to use matlabpool effectively.