Numerical integration with spmd on distributed arrays

1 vue (au cours des 30 derniers jours)
Domenico Valerio
Domenico Valerio le 21 Mai 2021
Modifié(e) : Alvaro le 19 Jan 2023
Hi everybody,
I'm trying to optmize a code which integrates with trapz two arrays. Since the operation is very time-consuming, I'm using spmd to subdivide the integration interval (the arrays) in order to "dividi et impera" an then sum the partial results of workers. I already have the arrays to be integrated. I have distributed the arrays all over the worker and performed the integration. It works well, excepted for one thing: the integration is correctly performed all over the "portion" of arrays, but on the boundary it's missing. In other words, if my vector is 1x8002 elements, the code distributes the arrays into two parts of 1x4001 (1:4001 and 4002:end) to each worker and integrates them separately, but the integration between 4001 and 4002 is missing.
How can I solve for it?
Attached the portion of the code:
Thank you,
xprimo_distr = distributed(xprimo); % first vector for trapz
P_distr = distributed(P); % second vector for trapz
for ii = 1:Nphi
for jj = 1:Nxprimo
lambda_primo(jj,:) = interp1(X, lambda(ii,:)', xprimo(jj), 'linear', 0);
lambda_primo_distr = distributed(lambda_primo); %third vector for trapz
xprimo_w = getLocalPart(xprimo_distr); % distribution to workers
P_w = getLocalPart(codistributed(P_distr,codistributor1d(1))); % distribution to workers (it's a matrix, so the division is made by rows)
lambda_primo_w = getLocalPart(codistributed(lambda_primo_distr,codistributor1d(1))); % distribution to workers (it's a matrix, so the division is made by rows)
lambda_plus = trapz(xprimo_w, P_w.*lambda_primo_w); % integration
tot_lambda_plus = gplus(lambda_plus,1); % collect the results
comp_lambda_plus(ii,:) = tot_lambda_plus{1}; % save the row-value for each phi-ii

Réponses (1)

Alvaro le 19 Jan 2023
Modifié(e) : Alvaro le 19 Jan 2023


En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by