SPMD in matlab - how to store the returned data?

3 次查看(过去 30 天)
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 个评论
Teng Zeng
Teng Zeng 2020-3-6
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!

请先登录,再进行评论。

回答(1 个)

Edric Ellis
Edric Ellis 2015-5-5
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by