improving the speed of parallel optimization
2 次查看(过去 30 天)
显示 更早的评论
Hi, I am trying to optimize in parallel but the speed is increased just slightly by using parfor. Do you have any further recommendations? Thanks!
parfor i = 1:M
options = optimset('MaxFunEvals',Inf,'MaxIter',10,...
'Algorithm','interior-point','Display','iter');
startTime = tic;
[x(:,i),fval(:,i)] = fmincon(@(x)revenue(price(1:N,1),ro,g,eff,x,N,k1,init_s(i),inFlow(:,i),alpha_par(i),b_par(i)),x0(1:2*N,i),A,b(:,i),Aeq,beq(:,i),LB(:,i),UB(:,i),[],options);
time_fmincon_parallel = toc(startTime);
fprintf('Parallel FMINCON optimization takes %g seconds.\n',time_fmincon_parallel);
end
0 个评论
回答(2 个)
Walter Roberson
2018-6-4
Instead of running the fmincon calls in parallel, try running them in a loop, but using the option UseParallel to allow parallel estimation of the gradient.
Remember, it is common for Parallel processing to be slower than serial, depending on the amount of data to be transferred compared to the amount of work to be done per iteration, and taking into account that non-parallel workers can use the built-in parallelization of some operations on large "enough" matrices by calling into LaPACK / MKL.
9 个评论
Walter Roberson
2018-6-21
If I recall correctly, with N even close to that large, asking matlabFunction to optimize the code takes far far too long, so I do not think you are going to be able to take advantage of that.
Matt J
2018-6-21
编辑:Matt J
2018-6-21
This is a more optimal implementation of storage(),
function S=storage(init_s,inFlow,x,N)
D=inFlow-totalflow(x,N);
D(1) = D(1) + ( init_s(1) + D(1) );
S=cumsum(D);
end
14 个评论
Matt J
2018-6-26
编辑:Matt J
2018-6-26
I have implemented those suggestions and its a bit faster
How fast is it now? It should have been a lot faster than what you were doing.
Do you know maybe how I can run it with quadprog instead of fmincon?
The problem doesn't look quadratic, except maybe when b_par=1.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!