How can I use fmincon into the SPMD when the parameters of objective function differs from on workers to another?
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
the overall structure of my code is here:
%some parameters are defined before
%exclusive values for parameters for each workers are defined
%for exapmle, "u" is a parameter in cell array that each cell belongs to a worke: u{1} for worker 1
spmd
for
fun=@(x) norm(x-u)
fmincon
%other calculations based on the output of fmincon that provides "u" for the next itteration
end
end
when the fun is in the spmd block, I face the error of anonymous funtion that says I can not define the function into the spmd.
if the dunction goes out of the spmd, there is no more access to the workers data (calculated "u" in the example).
can anyone say how can handle this problem?
0 个评论
回答(2 个)
Matt J
2021-1-19
You can use spmd to create the u data on the workers, but then use a parfor loop to do the optimizations.
spmd
u=labindex; %create composite
end
c=parallel.pool.Constant(u);
parfor i=1:numel(u)
uValue=c.Value
fun=@(x) (x-uValue).^2;
w{i}=fmincon(fun,0);
end
6 个评论
Matt J
2021-1-24
In the parfor loop, can I tell to a worker to stop if some conditions are met?
That's what stop_flag is for.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!