Info
This question is closed. Reopen it to edit or answer.
Why the optimization variables is same on each processor when using parallel optimization toolbox?
2 views (last 30 days)
Show older comments
Hi, I am a beginner of parallel optimization.
I used the testing code from Minimizing an Expensive Optimization Problem Using Parallel Computing Toolbox, and made a slight change to monitor the optimization variables of each processor(see below).
function f = expensive_objfun(x)
%EXPENSIVE_OBJFUN An expensive objective function used in optimparfor example.
% Copyright 2007-2013 The MathWorks, Inc.
%% display processor and optimization variables
task=getCurrentTask;
if isempty(task)
taskid='~';
else
taskid=num2str(task.ID);
end
disp(['Task' taskid char(9) 'x: ' num2str(x)])
%% objfcn from MathWorks
% Simulate an expensive function by pausing
pause(0.1)
% Evaluate objective function
f = exp(x(1)) * (4*x(3)^2 + 2*x(4)^2 + 4*x(1)*x(2) + 2*x(2) + 1);
The command window shows optimization variable of each iteration on each processor, and what surprised me is the variables are totally same!
Task~ x: -1 1 1 -1
Task1 x: -1 1 1 -1
Task2 x: -1 1 1 -1
Task3 x: -1 1 1 -1
Task4 x: -1 1 1 -1
Task~ x: -4.2359 2.4679 -1.5394 0.80007
Task~ x: -2.6179 1.7339 -0.26972 -0.099966
Task1 x: -2.6179 1.7339 -0.26972 -0.099966
Task2 x: -2.6179 1.7339 -0.26972 -0.099966
Task4 x: -2.6179 1.7339 -0.26972 -0.099966
Task3 x: -2.6179 1.7339 -0.26972 -0.099966
Task~ x: -2.3713 2.3761 0.40751 0.35945
Task1 x: -2.3713 2.3761 0.40751 0.35945
Task2 x: -2.3713 2.3761 0.40751 0.35945
Task3 x: -2.3713 2.3761 0.40751 0.35945
Task4 x: -2.3713 2.3761 0.40751 0.35945
Task~ x: -1.5812 3.273 0.18625 0.43047
Task1 x: -1.5812 3.273 0.18625 0.43047
Task2 x: -1.5812 3.273 0.18625 0.43047
Task3 x: -1.5812 3.273 0.18625 0.43047
Task4 x: -1.5812 3.273 0.18625 0.43047
Task~ x: 2.07788 11.3179 1.36175 1.16423
Task~ x: 0.24833 7.2955 0.774 0.79735
Task~ x: -0.66645 5.2842 0.48013 0.61391
Task~ x: -1.1238 4.2786 0.33319 0.52219
Task1 x: -1.1238 4.2786 0.33319 0.52219
Task2 x: -1.1238 4.2786 0.33319 0.52219
Task4 x: -1.1238 4.2786 0.33319 0.52219
Task3 x: -1.1238 4.2786 0.33319 0.52219
Task~ x: -1.3194 4.9367 0.32417 0.27363
Task1 x: -1.3194 4.9367 0.32417 0.27363
Task2 x: -1.3194 4.9367 0.32417 0.27363
Task3 x: -1.3194 4.9367 0.32417 0.27363
Task4 x: -1.3194 4.9367 0.32417 0.27363
Task~ x: -1.4612 7.2753 0.13652 -0.23738
Task1 x: -1.4612 7.2753 0.13652 -0.23738
Task2 x: -1.4612 7.2753 0.13652 -0.23738
Task3 x: -1.4612 7.2753 0.13652 -0.23738
Task4 x: -1.4612 7.2753 0.13652 -0.23738
Could anyone please tell me why, thanks very much!
0 Comments
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!