SPMD in matlab - how to store the returned data?

5 views (last 30 days)
Noam
Noam on 3 May 2015
Commented: Teng Zeng on 6 Mar 2020
Hi,
I use SPMD for performing multi-data curve fitting with the optimization toolbox in MATLAB. I have n workers and 2n curves to fit. I use the following code to do the curve fitting in parallel:
modelfun = @(sig, f) normax( exp((-(time).^2)/sig.^2) .* sin( (2*pi*f);
costfun = @(Y) (@(x) sum( ( Y' - modelfun(x(1),x(2),x(3),x(4))).^2 ));
numIterD = distributed( (1:2*n) );
spmd
numIterLP = getLocalPart ( numIterD );
for n = numIterLP(1):numIterLP(end)
fprintf('working on %d''th curve ...\n', n);
costIter = costfun(normax( dataArray{n} ));
[p_est] = geneticAlg( numcoeff, LowConstr,UppConstr, costIter);
estData(n,:) = modelfun( p_est(1), p_est(2), p_est(3), p_est(4));
% Evaluating goodness of optimization and fit
res(n,:) = normax(dataArray) - estData';
goodness(n) = iGoodnessStructure(estData,[],res,dfe,N);
end
end
I get back 3 Composite arrays with size of the number of workers - n, instead of 2n parameter sets. I believe that the code return only the last calculation for each local part so half of the data gets lost. How can I index the output so all results are kept?
  1 Comment
Teng Zeng
Teng Zeng on 6 Mar 2020
Hi there, has this problem been resovled? I ran into exactly the same issure. I was able to retrieve value by indexing the worker from the returned composite object. However, the data recorded is only the last run of the program, which is not very ideal.. Thanks!

Sign in to comment.

Answers (1)

Edric Ellis
Edric Ellis on 5 May 2015
Each Composite contains the values computed on each worker. So, you should be able to index into e.g. res to get the values from each worker.

Community Treasure Hunt

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

Start Hunting!