MATLAB function: makes 4 recursive calls. I have a 4 core processor. Is it possible to parallelize?

I have a 4-core processor and there is a recursive Matlab function that makes four recursive calls:

function J = do_stuff(I) if some_condition(I) J = blah_blah(I); else [I1,I2,I3,I4] = split4(I); J1 = do_stuff(I1); J2 = do_stuff(I2); J3 = do_stuff(I3); J4 = do_stuff(I4); J = join4(J1,J2,J3,J4); end 

Is there a way to assign do_stuff(I1) to core 1, do_stuff(I2) to core 2, and so on to core 4?

+4
source share
4 answers

There is no way to do this in the base Matlab, but the Parallel Computing Toolbox provides this (and other) functionality. You must create an array [I1,I2,I3,I4] , and then use a parallel map to display do_suff in this array.

+6
source

It is not possible to assign a calculation directly to a processor in MATLAB. However, there are several different ways to use more processors.

First, there are several operations that are implicitly mulitthreaded in MATLAB. If blah_blah () is heavily dependent on linear algebra or elementary calculations such as sin or log, then the work will usually be distributed across your 4 cores by the operating system. This functionality comes with MATLAB.

Parallel Computing Toolbox gives you more access to explicit multiprocessing. Typically, parfor is used to work with various independent data segments. There are also other tools that allow you to write a single piece of code that works with various pieces of data assigned to different computing workers.

+3
source

According to other respondents, the Parallel Computing Toolbox provides the necessary functionality. But before you start buying and implementing your function, think about what you want to do at the first level of recursive calls. Be that as it may, your pseudo-code will create 4 more calls for each of the originals 4. This may or may not be what you want.

Personally, I think that I would approach this not with the parallel_map function, but with the built-in task scheduler and createTask.

0
source

If you don't want to pay for the Parallel Computing Toolbox, you can take a look at this multi-core package . Depending on what you are working on and how much data you have, this may work for you.

Just be careful with the settings you use and the way you configure your data, because it is very easy to lose any benefits from parallelizing intermediate loads and save the package.

Hope this helps.

0
source

All Articles