0

I have written a class which among other things fits my model to my data using a simulated annealing algorithm. I call it multiple times (each time incrementing one of the parameter values) within a loop. There is an outer loop which runs the aforementioned steps multiple times again. Then I take the average over the number of runs.

So the code looks something like this:

parfor k=1:number_of_runs
for j=1:number_of_times_the_parameter_changes

MyObject.RunSimulatedAnnealingAlgorithm();

ParameterEstimates(:,:,j,k) = MyObject.ParameterEstimates;

end
end

The problem is that using parfor does not speed up execution. Any ideas of what may have gone wrong?

sigma
  • 216
  • 1
  • 4
  • Pay attention at the warnings produced by MATLAB inside the `parfor` loop. I am not so good at `parfor` debugging, but your matrix `ParameterEstimates` looks big, so if you are connected to 4 workers, are you sure that you have enough RAM to hold 4 of such matrices at a time? – Autonomous Sep 05 '14 at 20:25
  • Yeah, I am pretty sure. It is actually not that big. I would say it typically goes up to size of 12 * 5 * 30 * 30 (double precision), or about 432 kB on 64 bit system. – sigma Sep 05 '14 at 22:01
  • Read 'examples' section in [this](http://www.mathworks.com/help/distcomp/parfor.html) link. It says that if the inner function computation is large enough, then `parfor` will be faster than the corresponding `for`. So if your inner for loop takes a lot of time, then ideally `parfor` should be faster. – Autonomous Sep 06 '14 at 01:31

0 Answers0