How to improve the speed of this parfor loop?

1 view (last 30 days)
Adithya
Adithya on 10 Nov 2014
Edited: Edric Ellis on 10 Nov 2014
I currently have the following code as part of a function in a parallel for loop:
parfor k = 1:K(v)
[D3_temp(k,:), phy1_temp(k,:), phy2_temp(k,:), phy3_temp(k,:), phy4_temp(k,:)] = ...
recursions(R_test, R, Nv, K, m, v, k, D);
end
where m, v are outer loop indices. Nv, K are relatively small arrays. D, R_test, R are huge arrays and accessed in a complicated manner. recursions is a local function I had to write to allow the code to run with parfor. The outputs of recursions are not initialized outside the parfor loop because I found I could improve the speed by not initializing them. The inputs of recursions are only read from, never written to within the function.
I had to write the local function recursions because parfor would not allow me to access D, R_test, R in the way I wanted. I tried using a nested function, but MATLAB said it would not allow nested functions within parfor. The typical value for K(v) is 100.
Currently the code takes a lot less time to execute when I replace parfor with 'for', but it only uses 1 core for this. My computer has a 3 GHz octa-core processor with 32 GB RAM. I have set my parallel profile to use 7 workers.
Can anyone help me improve the speed? Is parfor the best solution or is it better to use something else from the parallel computing toolbox?

Answers (0)

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!