Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to improve volume creation speed?

2 vues (au cours des 30 derniers jours)
Thiago Motta
Thiago Motta le 4 Mar 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello community!
I'm trying to build a new volume (3D) out of some contour (2.5D) information. The contours were constructed every 1mm in each direction, that means I've got contours on the XY, XZ and YZ planes, each one on a different file.
These are the tests I've performed
clear;
clc;
c = parcluster('local'); % build the 'local' cluster object
nw = c.NumWorkers; % get the number of workers
len = 800;
vol = false(len, len, len);
arrayX = randi(len, len, 1);
arrayY = randi(len, len, 1);
arrayZ = randi(len, len, 1);
tic;
for i = 1 : len
vol(arrayX(i), arrayY(i), arrayZ(i)) = true;
end
disp(['Method 1 time: ', num2str(toc), ' seconds.']);
vol2 = false(len, len, len);
tic;
vol2(arrayX(:), arrayY(:), arrayZ(:)) = true;
disp(['Method 2 time: ', num2str(toc), ' seconds.']);
vol3 = false(len, len, len);
tic;
vol3(arrayX, arrayY, arrayZ) = true;
disp(['Method 3 time: ', num2str(toc), ' seconds.']);
vol4 = false(len, len, len);
tic;
volCell = cell(1, nw);
cellX = cell(1, nw);
cellY = cell(1, nw);
cellZ = cell(1, nw );
ratio = uint16(floor(len/nw));
for i = 1 : nw-1
volCell{i} = false(len, len, len);
cellX{i} = arrayX((i-1)*ratio+1:i*ratio);
cellY{i} = arrayY((i-1)*ratio+1:i*ratio);
cellZ{i} = arrayZ((i-1)*ratio+1:i*ratio);
end
volCell{nw} = false(len, len, len);
cellX{i} = arrayX((nw-1)*ratio+1:len);
cellY{i} = arrayY((nw-1)*ratio+1:len);
cellZ{i} = arrayZ((nw-1)*ratio+1:len);
for i = 1 : nw
currVol = volCell{i};
currX = cellX{i};
currY = cellY{i};
currZ = cellZ{i};
currVol(currX, currY, currZ) = true;
volCell{i} = currVol;
end
for i = 1 : nw
vol4 = bitor(vol4, volCell{i});
end
disp(['Method 4 time: ', num2str(toc), ' seconds.']);
disp(['Vol is equal to Vol2? ', num2str(isequal(vol, vol2))]);
disp(['Vol is equal to Vol3? ', num2str(isequal(vol, vol3))]);
disp(['Vol is equal to Vol4? ', num2str(isequal(vol, vol4))]);
Method 1 time: 0.0023944 seconds.
Method 2 time: 0.41915 seconds.
Method 3 time: 0.41841 seconds.
Method 4 time: 3.9272 seconds.
Vol is equal to Vol2? 0
Vol is equal to Vol3? 0
Vol is equal to Vol4? 0
For some reason, vol2, vol3 and vol4 are all different to vol and I cant understand why they are ending up being so different.
Method 2 and 3 (which yields the same result, but that are different than Method 1) are faster than Method 1 for small len sizes, but Method 1 gets about 200x faster for bigger sizes. I just cant figure out why.
Method 4 is just plain slow. My idea here was to split up the computation so it could be run in multiple cores, but the splitting, joining and sending to multiple threads seems to be taking longer than the filling part itself, so this is pointless.
Is there any other way to do this faster? To do it in multithreads? I dont have enough memory to run this on the GPU side.
Thank you.

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by