SPMD in matlab - how to store the returned data?
Afficher commentaires plus anciens
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 commentaire
Teng Zeng
le 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!
Réponses (1)
Edric Ellis
le 5 Mai 2015
0 votes
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.
Catégories
En savoir plus sur Parallel Computing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!