Two instances of fmincon using parallel in each

1 view (last 30 days)
gtdj
gtdj on 20 Feb 2011
I don't know that it is a common question here or not. I used to run fmincon in parallel by
matlabpool(4)
fmincon(@(x)myfun(x,a));
matlabpool close
From my understanding fmincon use maximum processor of 4.
Now I want to run two optimization problems with change of a and I have 8 cores processor in local. Traditionally using 4 cores, I have
matlabpool(4)
xa = fmincon(@(x)myfun(x,a));
matlabpool close
matlabpool(4)
xb = fmincon(@(x)myfun(x,b));
matlabpool close
What I should do to run both
xa = fmincon(@(x)myfun(x,a));
xb = fmincon(@(x)myfun(x,b));
at the same time. I try to run open the pool to 8 over myfunction that has fmincon inside something similar to
matlabpool(8)
xx = dfeval(@(c)myfmincon(x,c),{a,b},'Configuration', 'local');
matlabpool close
...
function xx = myfmincon(x,c)
xx = fmincon(@(x)myfun(x,c));
end
This one stay running forever without running myfun. And I also try to open the pool in half in my function instead similar to
xx = dfeval(@(c)myfmincon(x,c),{a,b},'Configuration', 'local');
...
function xx = myfmincon(x,c)
matlabpool(4)
xx = fmincon(@(x)myfun(x,c));
matlabpool close
end
This doesn't work it said that I need to running manually.
What can I do?

Answers (1)

Konrad Malkowski
Konrad Malkowski on 21 Feb 2011
It appears that you have two questions.
Q1. How many cores/processors can fmincon use at a time?
If you set the UseParallel option to always then fmincon will use up to 8 local workers (MATLAB labs) to perform the optimization. The number of local workers that fmincon uses is determined by the number of cores/processors available on your system. With Parallel Computing Toolbox the maximum number of workers that you can use is 8. However, if you have MDCS, the number of workers used by fmincon is limited by the number of MDCS licenses.
Q2. How can I execute two fmincon calls at the same time in parallel, with each fmincon call using 4 workers?
On a local machine with 8 cores it is currently not possible to execute two calls to fmincon with each call using 4 workers at the same time (in parallel). However, it is possible to execute two calls to fmincon, at the same time (in parallel) with each fmincon using 3 workers. To execute these two separate evaluations of fmincon in parallel you will need to use the batch job API. For example, let's say that you have the following function:
function xx = myfmincon(x,c)
% UseParallel option is set to 'always'
xx = fmincon(@(x) myfun(x,c));
end
Then to evaluate two instances of this function in parallel you will need to use the following series of commands:
sched = findResource('scheduler','type','local');
job1 = batch(sched, @myfmincon, 1, {x1,c1}, 'Matlabpool',3);
job2 = batch(sched, @myfmincon, 1, {x2,c2}, 'Matlabpool',3);
wait(job1);
wait(job2);
xx1 = getAllOutputArguments(job1);
xx2 = getAllOutputArguments(job2);
For more information of the batch command please refer to the following documentation page:

Categories

Find more on Introduction to Installation and Licensing 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!