Speeding up the computation

1 view (last 30 days)
Uerm
Uerm on 24 Jan 2020
Answered: Gaurav Garg on 29 Jan 2020
Hi, I have run the following code, which takes ages to complete. Even when I use high performance computers, after several days, the computation has still not completed. Is there any way, I can speed up the computation? Maybe by writing it another way? The code is here:
max_wavelet_level = 8;
nn = 5;
for i = 1:length(Data)
i
patient = tensor{1,i};
for k = 1:size(patient,1)
for j = 1:size(patient,3)
WDEC{1,i}(k,:,:,j) = single(modwt(tensor{1,i}(k,:,j),max_wavelet_level,'db4'));
for l =1:max_wavelet_level+1
[imf,res] = emd(squeeze(WDEC{1,i}(k,l,:,j)),'Display',0);
pad_size = max(0,nn-size(imf,2));
pad = zeros(size(imf,1),pad_size);
padded_imf = cat(2,imf,pad);
EMD{1,i}(k,l,:,:,j) = single(padded_imf(:,1:nn));
end
end
end
end
I am running discrete wavelet transform on my signal. Subsequently, I run the EMD algorithm on the subsignals.
  1 Comment
Mohammad Sami
Mohammad Sami on 25 Jan 2020
try profiling to see which part of your code is taking the longest.

Sign in to comment.

Answers (1)

Gaurav Garg
Gaurav Garg on 29 Jan 2020
Hi,
You can use parfor loop to run your for loop on multiple workers.
However, parfor can only be used when there aren’t any dependencies between different wokers/threads which seems to be true in your case. Moreover, parfor loops cannot be nested (parfor cannot be placed inside another parfor).
So, you can consider running parfor on either the first loop (parfor i = 1:length(Data)), or any other loop which should run fine too.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!