# Numerical integration with spmd on distributed arrays

2 views (last 30 days)
Domenico Valerio on 21 May 2021
Edited: Alvaro on 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,
Domenico
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);
end
lambda_primo_distr = distributed(lambda_primo); %third vector for trapz
spmd(N_worker)
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
end
comp_lambda_plus(ii,:) = tot_lambda_plus{1}; % save the row-value for each phi-ii
end

Alvaro on 19 Jan 2023
Edited: Alvaro on 19 Jan 2023