Reading out vector by index matrix too slow?
Show older comments
Hey folks, I'm trying to implement a 3D acoustic source localization algorithm in real-time. Unfortunately, I've to handle a lot of data, i.e., big matrices. To avoid this problem and to avoid running out of memory, I generally work with index-matrices or -vectors. Right now, a special index-operation is the weak point of my implementation regarding processing time. The problem is as follows:
for k=1:270
... % Some code for block-processing (processing time negligible)
for j=1:5
for i=1:70
(1) tmp = sum( DataArray( idxCell{i,j}{1} ) , 2);
(2) ErgArray(:,i) = ErgArray(:,i) + tmp( idxCell{i,j}{2} );
end
end
end
I've pre-allocated memory for 'ErgArray'. I have to do the computations with a lot of data (which is already optimized):
size(tmp1) -> 142 x 1 (single)
size(idxCell{i,j}{1}) -> 142 x 5 (uint16)
size(idxCell{i,j}{2}) -> 51120 x 1 (uint16)
size(ErgArray) -> 51120 x 70 (single)
If I eliminate the second for-loop by vectorization, the whole computation lasts much longer. According to profile and tic/toc, (1) requires 4.8 s, and (2) 19.6 seconds. I work in single-core mode, i.e., using -singleCompThread. The whole process should should take ab to (at most) 3 seconds. Using mex-files doesn't reduce the processing time.
By the way: idxCell{i,j}{1} contains specific indices. Using this cell avoids using complicated filters, i.e., very (!) big matrices and for-loops.
Have you ever encountered such problem? Why does vectorization take more time than using an additional for-loop? Does a more efficient computation exist? If yes, which one? Is this way of filtering inefficient?
PS: Computer-Info: 1) AMD FX(tm)-8150 Eight-Core Processor 2) 1.4 GHz 3) 2048 kB Cache size 4) 15 GB RAM
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!