arrays - Sorting coordinates of point cloud in accordance with X, Y or Z value -
A
for example, a series of points in 3D (X, Y, Z) Coordinate is:
& gt; & Gt; A = [1 2 0; 3 4 7; 5 6 9; 9 5; 7 8 4]
A = 1 2 0 3 4 7 5 6 9 5 7 8 4
I want to sort the matrix in terms of values "y" (second column) values.
Here is the code I am using:
& gt; & Gt; Tic; [~, Public] = sort (A (,, 2)); SortedA = A (loc, :) toc;
SortedA = 9 0 5 1 2 3 4 7 5 6 9 7 8 4
Passed time ** 0.001525 ** is seconds
However, this can be very slow for a large set of data. I appreciate it if someone knows a more efficient approach.
introductory discussion
This answer will mainly talk about this How to solve a problem, a computable skilled can tap into the GPU
. The problem presented in the question was the solution code -
[~, loc] = Sort (a (,, 2)); Sorted A = A (location, :); There are basically two parts - - Select the second column, sort them and get the sorted index.
- In the rows of the input matrix with the index sorted index
Now, part 1
is an intensive count, which can be ported to GPU
the proposed solution
Therefore, considering all but, part 2
can be done on a CPU
when a sequencing is done. This will be an efficient GPU
solution -
GA = GPRRA (A (,, 2)); % // jpu [~, glock] = only the second column of the input matrix for the sort (ga); GPU SortedA =% on calculation Sort index (glow), :); Get the% // sorted index back on the CPU with `assembled`% and then use them to sort
benchmarking
Next benchmark To compare the code against the original solution to the GPU
version, please keep in mind that since we were originally referred to as solution, the GPU
code on different hardware Running CPU
, Benchmark results vary from system to system You can.
Here is the benchmark code -
N = 3000000; % // datasize (number of rows in input) A = rand (n, 3); % // Random Large input Disp ('------------------' with basic solution on CPU) Tic [~, folk] = sort (A (,, 2) ); Sorted A = A (location, :); TCC, Clear Sorted A Public Disp ('------------------) with the proposed solution on GPU) TIC GA = GPU (A (,, 2)); [~, Glock] = sort (ga); Sorted A = A (Collect (Glock), :); Toc
Here are the benchmark results -
------------------ CPU time on the basic solution It has been 0.795616 seconds. ------------------ With the proposed solution of GPU, the time has passed since 0.465643 seconds.
So if you have enough GPU
, then there is more time to exclude GPU
to sort out the related problem MattelBag offers such easy GPU
porting solutions.
System Configuration
MATLAB Version: 8.3.0.532 (R2014a) Operating System: Windows 7 RAM: 3GB CPU model: Intel® Pentium Processor E 5400 (2 M cache, 2.70 GHz) GPU model: GTX 750Ti 2GB
Comments
Post a Comment