How to increase speed of a multi-vector calculation

3 vues (au cours des 30 derniers jours)
moh mor
moh mor le 18 Déc 2023
Commenté : moh mor le 18 Déc 2023
Hello,
I have implemented a loop like this:
for coorC = 1:numel(y1f),
AF_Nunir(:,coorC) = AF_surff( x1f.', y1f.', x1f(coorC), y1f(coorC), (Xr.')*0.015, (Yr.')*0.015 ,K);
end
and:
function z = AF_surff(u , v, u0 , v0 , X, Y , K )
distance = (sqrt((X-u0).^2 + (Y-v0).^2 + 0.4^2) - sqrt((X - u).^2 + (Y - v).^2 + 0.4^2));
AF_out1 = sum(exp(1j*(K.').*(distance(:).')),1);
AF_out2 = sum(reshape(AF_out1,[numel(X),numel(u)]),1);
z = AF_out2;
end
where "K", "Xr", "Yr", "x1f", and "y1f" are vector. I could implement this code using multiple nested "for" loop. But, I'd rather using vector computation in order to increase running speed. Above block must be rUn multiple times in our code, So it is crucial to implement this blcok efficiently. This takes 145s in a "core i9 12900K" CPU. What is your advice to perform this manipulations efficiently? I've heard about parallel computing. Does it effectively play a crucial role for solving this kind of problem?
Any help would be appreciated.
Thank you

Réponses (1)

Rik
Rik le 18 Déc 2023
The iterations are not interdependent, so you should be able to use a parfor loop instead.
You could consider performing those conjugations (the .'), since those take up time every iteration.
Another speedup would be to replace distance(:).' by a call to reshape.
  1 commentaire
moh mor
moh mor le 18 Déc 2023
Than you. I've not heard already about it.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by