multiple optimization problems under parfor
이전 댓글 표시
Hi all,
I have encounted an issue when i tried to run 10000-by-9 optimizations under parfor. Don't really know what went wrong though.
Here's the code,
function [min,max]=opt_iden_set(params,constr,new_sol_array)
%input:
% params: a 9 by 1 vector of optimvar type
% constraints: M by 10 optimconstr type
%output: min max of each variable.
%min: M by 9
%max: M by 9
M=size(constr,1);
x0.q=0;
x0.d=0;
x0.t=0;
x0.g=0;
x0.ft=0;
x0.tb=0;
x0.vv_bar=1;
x0.phi_bar=2;
x0.rho_bar=0;
min=zeros(M,9);
max=zeros(M,9);
tic
poolobj = parpool('local');
disp("Finding identified sets...")
for i=1:M
if i>1 && all((new_sol_array(i,:)==new_sol_array(i-1,:)),2)
min(i,:)=min(i-1,:);
max(i,:)=max(i-1,:);
else
constraints=constr(i,:);
parfor p=1:9
prob = optimproblem;
prob.Constraints=constraints;
options = optimoptions('fmincon',Display = 'none');
%use fmincon, ref: https://www.mathworks.com/help/optim/ug/optimization-decision-table.html
prob.Objective= params(p);
prob.ObjectiveSense='minimize';
[~,fval]= solve(prob,x0,Options=options);
min(i,p)=fval;
prob.ObjectiveSense='maximize';
[~,fval]= solve(prob,x0,Options=options);
max(i,p)= fval;
end
end
end
disp("Identified sets found!")
toc
delete(poolobj)
end
Here params is a vector of 9 optimvars, constr is a 10000 by 10 optimconstr type variable, and new_sol_array is simply the string version of constr so i can compare. Each row of constr contains the constraints for a single optimization problem, which is min/max of elements of params. I want to parallel the optimization for each (or M rows), because there seem to be 10000 by 9 independent optimization problems.
However, I keep getting things like
OptimizationVariables appearing in the same OptimizationProblem must have distinct "Name" properties.
Make a new variable with a different "Name" property, or retrieve the original variable using the Variables property.
or
Warning: A worker aborted during execution of the parfor loop. The parfor loop will now run again on the remaining workers.
> In distcomp/remoteparfor/handleIntervalErrorResult (line 245)
In distcomp/remoteparfor/getCompleteIntervals (line 395)
In parallel_function>distributed_execution (line 746)
In parallel_function (line 578)
Error using distcomp.remoteparfor/getCompleteIntervals
The parallel pool that parfor was using has shut down. To start a new parallel pool, run your parfor code again or use parpool.
Exception in thread "CommGroup select thread com.mathworks.toolbox.distcomp.pmode.io.DirectCommunicationGroup@299d3663": java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:717)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:957)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1367)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at com.mathworks.toolbox.distcomp.pmode.io.DirectCommunicationGroup$ChannelHandle.<init>(DirectCommunicationGroup.java:1168)
at com.mathworks.toolbox.distcomp.pmode.io.DirectCommunicationGroup.doSelect(DirectCommunicationGroup.java:799)
at com.mathworks.toolbox.distcomp.pmode.io.DirectCommunicationGroup.run(DirectCommunicationGroup.java:664)
at java.lang.Thread.run(Thread.java:748)
Preserving jobs with IDs: 3 because they contain crash dump files.
You can use 'delete(myCluster.Jobs)' to remove all jobs created with profile local. To create 'myCluster' use 'myCluster = parcluster('local')'.
Error using internal.matlab.desktop.editor.clearAndSetBreakpointsForFile
An internal runtime error occurred.
Warning: 5 worker(s) crashed while executing code in the current parallel pool. MATLAB may attempt to run the code again on the remaining workers of
the pool, unless an spmd block has run. View the crash dump files to determine what caused the workers to crash.
Warning: 5 worker(s) crashed while executing code in the current parallel pool. MATLAB may attempt to run the code again on the remaining workers of
the pool, unless an spmd block has run. View the crash dump files to determine what caused the workers to crash.
when i tried to pull the parfor in the outmost for loop.
Does anyone know why? I could really use some help here. Thanks!
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!