How to increase speed of a multi-vector calculation

3 visualizaciones (últimos 30 días)
moh mor
moh mor el 18 de Dic. de 2023
Comentada: moh mor el 18 de Dic. de 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

Respuestas (1)

Rik
Rik el 18 de Dic. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by