MATLAB: TimeLimit option in Patternsearch being ignored

parallel computingParallel Computing Toolboxpatternsearchtime limit

Hi everyone,
I have a problem which I am solving via the patternsearch function. Essentially, I have an objective function (func) which includes a parfor loop, using the parallel computation toolbox and a (large) parpool (several hundred cores). I have an issue in that I need to ensure that this runs within a certain time frame, which is proving difficult and I'm not sure why.
When I set the time-limit parameter in the options, patternsearch does not adhere to it. It will eventually time out, but the period is approx 2-4 times longer than the option set. The same set up in a different solver (ga) adheres exactly, without an issue.
Does anyone know how or why this is occurring? Any suggestions?
My intuition is that it has to do with the communication between the parpool agents, similar to a documented issue with ga when used in parallel, but since this is not a parallel computation I don't think this can be the same issue.
For example, here are the same problem being run with the same time-limit in patternsearch and ga:
PS:
Time limit reached: increase options.TimeLimit.
Elapsed time is 84952.876117 seconds.
GA:
Optimization terminated: time limit exceeded.
Elapsed time is 36458.878759 seconds.

Best Answer

I am very sorry to say that you got bit by a bug. We will fix it as soon as we can.
Here is the bug. patternsearch uses the cputime function to measure the amount of time that has passed. However, when run in parallel, this measurement is done for the host machine, not the parallel workers. So the host machine sends work to the workers and does not incur cputime while waiting for the results. As a result of this behavior, as you found, patternsearch does not believe that much time has passed, because, when run in parallel, it ignores the time that the workers take. So it does not respond to the time limit you set, a real bug.
Again, I apologize for the bug. The fix will be to use tic and toc to measure time. If you are brave, you can try to edit patternsearch to take a more sensible view of time using tic/toc.
Alan Weiss
MATLAB mathematical toolbox documentation