MATLAB: function makes 4 recursive calls. I have a 4-core processor. Can I parallelize?
matlab, parallel-processing, recursion
Solution
There is no way to do this in basic Matlab, but the Parallel Computing Toolbox provides this (and other) functionality. You would create an array `[I1,I2,I3,I4]`, then use parallel map to map `do_suff` across that array.
Problem
I have a 4-core processor and have a recursive Matlab function which 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 for me to assign `do_stuff(I1)` to core 1, `do_stuff(I2)` to core 2, and so on up to core 4?