MATLAB Answers

How can I use fmincon into the SPMD when the parameters of objective function differs from on workers to another?

41 views (last 30 days)
Bill Masters
Bill Masters on 18 Jan 2021
Commented: Matt J on 24 Jan 2021
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
fun=@(x) norm(x-u)
%other calculations based on the output of fmincon that provides "u" for the next itteration
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?


Sign in to comment.

Answers (2)

Matt J
Matt J on 19 Jan 2021
You can use spmd to create the u data on the workers, but then use a parfor loop to do the optimizations.
u=labindex; %create composite
parfor i=1:numel(u)
fun=@(x) (x-uValue).^2;


Show 3 older comments
Matt J
Matt J on 24 Jan 2021
I don't see how the "parfor loop does not meet the goal". The parfor loop I outlined is solving a different problem with its own parameters on each worker by virtue of the fact that uValue is different on the different workers...
Regardless, what aboud Sean's proposal to use parFeval?
Bill Masters
Bill Masters on 24 Jan 2021
let me make my last comment clear by a question: In the parfor loop, can I tell to a worker to stop if some conditions are met? while the others continue to computations.
about the parfval; I have not used it so far, I'll give it a try to see how it works and if it can be helpful. thanks.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by