Hi community,
this is the first time I couldn't find a solution for my problem by searching the forum, so i decided to post it.
I have a bigger function which uses fminsearch with an anonymous function + additional parameters in a spmd-block. I don't know how to pass these additional Data to my user-fct.
For understanding my problem I generated a minimal-expample. (I know parallel computing makes no sense for this optimization, but my problem is much bigger and takes a long time to calculate):
function [] = start() for i=1:10 p=i*10; min = fminsearch(@(x)target(x,p),[10]) end %function to be minimized
function [val] = target(x,p) val = (x-p)^2; endend
Now, I want to calculate the for-loop in several threads. So I decided to use a spmd-block (also tried parloop,…). I get something like this:
function [] = start() global p; x = []; p = []; fh_target = @(x)target(x); matlabpool 5; spmd for i=labindex:numlabs:100 p=i*10; min = fminsearch(fh_target,[10]) end end matlabpool close; %function to be minimized function [val] = target(x) val = (x-p)^2; endend
But i dont know how to pass the parameter p to the function target via a function-handle that is used by fminsearch. As you can see i tried it with global variables, but this doesn't work.
The parameter is not know before the for-loop or the spmd-block. I'm sorry for my english, but i hope aou understand my problem and somebody can help me.
Best Regards
Best Answer