From: Justin Bailey on
I'm running Matlab R2009b on an HP Pavilion (a6230n) desktop, W7 32-bit, AMD Athlon Dual Core Processor 5600+ (2.80 GHZ), and 3.00 GB of RAM.

My code executes a least squares curve fitting routing, using the lsqcurvefit function, on an equation w/ 18 free parameters. It fits upwards of 16000 data points and takes around 24 hours to converge. To investigate performance, I started paying attention to the Task Manager and was surprised to see that only one core was being utilized, maxing the total CPU usage at 50%. So... I installed the Parallel Computing Toolbox 4.2 and added the following lines of code...

matlabpool open 2
options = optimset('UseParallel','always',...)

Now, while running my code, it does jump above 50% initially, up to 100% even, but once the command reaches the lsqcurvefit function (takes a couple of minutes) it settles back down. Curiously, the 50% is now distributed between both cores...

Oh, and for reference, the RAM stays around 1 GB in both cases. Finally, and most importantly, my code takes the same amount of time to execute...

My question... Does Matlab support parallel computing on multicore processors when using lsqcurvefit? If it does, any ideas why I'm maxing at 50%? Should I upgrade to R2010a and version 4.3?

Please don't reply with vectorizing loops, pre-allocating, etc. If it can be done, I've done it...

THANKS in advance...
From: Matt J on
"Justin Bailey" <jbail3y+mathworks(a)gmail.com> wrote in message <i31obq$80o$1(a)fred.mathworks.com>...

> So... I installed the Parallel Computing Toolbox 4.2 and added the following lines of code...
>
> matlabpool open 2
> options = optimset('UseParallel','always',...)
[snip]
> My question... Does Matlab support parallel computing on multicore processors when using lsqcurvefit? If it does, any ideas why I'm maxing at 50%? Should I upgrade to R2010a and version 4.3?
=============

I'm fairly new to the Parallel Computing Toolbox, but I don't see why running matlabpool alone is expected to give you any speed-up. You're meant to be running additional toolbox commands, e.g., parfor, telling how you want chunks of code to be split across different workers.

I think it's also doubtful that native MATLAB routines like lsqcurvefit itself would be written to invoke Parallel Computing Toolbox features.

However, the speed of lsqcurvefit depends greatly on how long it takes to evaluate your fitting function F(x,xdata), which is clearly pretty intensive if you're running 24 hour jobs. You should probably be using parfor etc... to accelerate its evaluation and also the evaluation of its Jacobian, if applicable.
From: Justin Bailey on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i31pm9$nu$1(a)fred.mathworks.com>...
> ...
> However, the speed of lsqcurvefit depends greatly on how long it takes to evaluate your fitting function F(x,xdata), which is clearly pretty intensive if you're running 24 hour jobs. You should probably be using parfor etc... to accelerate its evaluation and also the evaluation of its Jacobian, if applicable.

=============

THANKS for the quick reply! I just replaced the applicable for loops with parfor loops and now my CPU usage is at 100%. So... I'm now sitting in front of my computer, giddy with anticipation...

I'm running a sample set, will reply with the percentage decrease in run time...
From: Justin Bailey on
In the sample set, I saw about a 20% reduction in the run time... Nice! THANKS again for your help...
From: Matt J on
"Justin Bailey" <jbail3y+mathworks(a)gmail.com> wrote in message <i32h65$el4$1(a)fred.mathworks.com>...
> In the sample set, I saw about a 20% reduction in the run time... Nice! THANKS again for your help...

I guess that means MATLAB does a pretty good job of parallelizing things, even without the Parallel Computing Toolbox...