MATLAB Answers

speeding up symmetric distance matrix computation

1 view (last 30 days)
gdgc
gdgc on 7 Dec 2017
Edited: gdgc on 7 Dec 2017
Hi everyone,
I'm currently working on some discrete vortex algorithm, and the main time consuming part can be sumed up by these few lines :
% initilization
n=1e4;
z=complex(rand(1,n),rand(1,n)); % vortices complex position
gam=rand(n,1); % circulation of vortices
% the part i'm trying to speed up
vel=gam./(z-z.');
vel(1:n+1:end)=0;
sumvel=sum(vel,1);
This involves the computation of a distance matrix, which is symmetric, so theoretically it should be possible to reduce the computation time of the z-z.' part.
I tried to use :
  • matlab dist and pdist builtin functions
  • custom (for i=1:n, for j=i+1:n) loops to avoid computing symmetric terms.
  • some mathworks file exchange functions, such as this one
Unfortunately, no one is faster than the brute force original one. Probably because it is using the full potential of vectorization. I precise that I don't need to compute it for thousands and thousands of points (5000 maximum), so I'm not limited or slowed down by huge memory transfer.
However I need to loop that process millions of time, and speeding it up a little would save me hours.
Any suggestion would be more than welcomed.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by