The latest Matlab releases (starting with R2007a) include support for multiple cores. However, Matlab will only take advantage of multiple cores in evaluating certain computations like an FFT or a FIR filtering operation. Matlab will never be able to determine if, for example, consecutive function calls in a for-loop are independent of each other.
With this package, I provide some MATLAB-functions realizing parallel processing on multiple cores on a single machine or on multiple machines that have access to a common directory.
If you have multiple function calls that are independent of each other, and you can reformulate your code as
resultCell = cell(size(parameterCell));
for k=1:numel(parameterCell)
resultCell{k} = myfun(parameterCell{k});
end
then, replacing the loop by
resultCell = startmulticoremaster(@myfun, parameterCell);
allows you to evaluate your loop in parallel. All you need to do is to start as many additional Matlab sessions/processes as you want slaves to work and to run
startmulticoreslave;
in those additional Matlab sessions. For example, if you want to evaluate a loop in parallel with four cores, the function startmulticoremaster.m must be started in one Matlab session, and the function startmulticoreslave.m in three other Matlab sessions.
No special toolboxes are used, no compilation of mex-files is necessary, everything is programmed in plain and platform-independent Matlab. If one of your slave processes dies - don't care, the master process will go on working on the given task.
Please consider that the communication between the processes, which is done by saving/loading temporary files, causes some overhead. Thus, if your function calls only need fractions of a second, the overhead will eat the advantage of the parallelization or can even lead to an increase of computation time. However, the multicore package can do several function evaluations after each other in every process before communicating again. In this way the overhead percentage can be lowered. See the help of function startmulticoremaster.m for more details.
Note: The Matlab multithreading capability (R2007a and higher) might terminate all the advantage gained by using the multicore package. So make sure that you UNcheck "Enable multihreaded computation" under File/Preferences/General/Multithreading in all involved Matlab sessions.
Dicuss with others users here: http://groups.yahoo.com/group/multicore_for_matlab
Keywords: Parallel processing, distributed computing, multiple core. |