How can I use the GPU to parallelize computation of average pairwise distances?
3 views (last 30 days)
Show older comments
I have a=rand(1, 1000) and b=rand(1, 1000), and I want to compute the average pairwise Euclidean distance between every point in A and every point in B. I don't need any of the individual distances.
I was able to get the Mandelbrot set GPU example running successfully on my computer, which walks you through either 1) just allocating arrays with gpuArray() and doing your computations, or 2) parallelizing with arrayfun() for much better performance.
However, I don't see a good way of shoehorning my problem into the arrayfun() requirements. One possibility might be to just form the matrix [a' repmat(b, 1000, 1)], which has a point of A in the first column of each row, and then all of the points of B in the rest of each row, and then if arrayfun() could just pass rows of this matrix as individual 'elements', that could work. But it wasn't clear to me if arrayfun() is capable of that.
Any thoughts?
Thanks.
0 Comments
Accepted Answer
More Answers (1)
Joss Knight
on 24 Jul 2018
See also https://www.mathworks.com/matlabcentral/answers/347838-computing-the-distance-between-a-grid-of-points-and-n-points-with-arrayfun-and-gpu for the version that doesn't require Stats Toolbox.
0 Comments
See Also
Categories
Find more on GPU Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!