Same code taking 15x longer to execute on a faster machine

I recently upgraded to a faster computer (from a 16Gb i7 processor to a 32Gb RYZEN processor with a 16Gb NIVIDIA RTX GPU (CUDA compatible)).
I used to execute the following code in a matter of 5-10 seconds on my older machine (MATLAB 2021a). Now it is taking >2 minutes on a way faster machine (MATLAB 2022b).
I think it is related to a certain memory allocation setting in MATLAB which I might have applied on my previous machine, but I can't remember it anymore.
Is there someone who could help me in resolving this issue, please? For example, which setting I could modulate to execute this code faster?
Or is it is related to the MATLAB version?
dE00=zeros(6,7362497,"single"); %dE00 refers to a numerical value of color difference
% lab_NF contains six CIELAB color values (L*, a* and b*) while labDB is a
% database of 7362497 CIELAB color values.
for nClrs=1:7362497
dE00(1:6,nClrs)=deltaE2000(lab_NF(1:6,1:3),labDB(nClrs,1:3));
end
Thanks in advance!

17 Commenti

DGM
DGM il 16 Nov 2022
Modificato: DGM il 16 Nov 2022
What function are you using? It's not either of these
because those doesn't support the way you're using it.
It's not this one
because that doesn't either, and it doesn't return the same size output.
So what is it?
Indeed, it is neither of the functions provided by you, I wrote my own DeltaE2000 code as per the original article
https://doi.org/10.1002/col.20070. I have attached the function though I am still wondering if it is the code that is poorly written, it should work even badly on a slow machine, not the opposite. My code works fine and it can take the inputs in a versatile manner. It is just very slow as compared to my old machine which is a big disadvantage for me, since I will be running this snippet multiple times.
Thanks !
What is the spec of the older computer? I guess it's intel base? Some people complain the slowness of AMD proessor possibly due to the library.
Have you run
bench
command?
I believe TMW claims many operations of small matrices is faster on R2022b (see the release note).
There is memory setting for java heap space, but I don't think it affects the computation speed.
BTW I run your code with random input
dE00=zeros(6,7362497,"single"); %dE00 refers to a numerical value of color difference
% lab_NF contains six CIELAB color values (L*, a* and b*) while labDB is a
% database of 7362497 CIELAB color values.
lab_NF = rand(6,3,'single');
labDB = rand(7362497,3,'single');
tic
for nClrs=1:7362497
dE00(1:6,nClrs)=deltaE2000(lab_NF(1:6,1:3),labDB(nClrs,1:3));
end
toc
It takes 90 seconds on my computer (Intel + Windows 11 + R2022b)
Thanks for your comment. Now that you say that, I do think the AMD processor could be the issue. Earlier I had an intel xeon i7 processor with half the RAM and no GPU and the same command worked better.
I ran the bench command and it shows clear superiority for sparse/2D and 3D operations for a simimar intel i7 processor. Only if I knew this before buying this expensive computer.
JAVA heap space would also reduce available memory for storing arrays, so I am a bit not sure about it.
Any other workaround? Should I try updating to Win 11 or degrading to MATLAB 2021a?
I don't believe the MATLAB version has anything to do with it. I see constant improvement of speed over time, but nothing that can explain x 15. Also your code does seem to use any gpu so Nvidia card is irrelevant.
Exactly, the GPU isn't involved so I think it is clearly an issue with Intel vs AMD. Though 90s is an improvement over 2.5 minutes, but slower than 5s-10s.
Do you think I could write this snippet better? I mean just this loop to perform faster or without loop with vectorisation?
I don't want to answer speeding up your code here. It's off topic.
Thanks for your help though, it makes more sense to why my code suddenly runs slower. Have a great day!
This has been a problem for a while.
The last posted Comment (posted about a month ago) expresses my frustration on this.
All of my computers have AMD processors because I prefer them.
.
@Star Strider can you please run the code (the one I posted) and post the result?
Thank you for your suggestion. However for me using the BLAS/LAPACK did not change the timing. Unfortunately it still takes the same amount of time. PS: I double checked to make sure that the AOC libraries were correctly installed.
What you should double check is this:
"I used to execute the following code in a matter of 5-10 seconds on my older machine "
I ran the code on both the machines before posting my question, and it still holds true. I think I just have a poor processor for MATLAB. In python my code goes way faster than before.
My laptop intel is quite recent, and it is no where 15 s, as I mention 90 seconds.
To be sure I'll download R2021a and do the same tic/toc.
I run gain the code on my Intel laptop
R2021a: 85 seconds
R2022b: 87 seconds
So it clearly is my machine which is just not great. I will try to rewrite the code more smartly to improve the processing duration. Thanks a lot.

Accedi per commentare.

 Risposta accettata

n = 32000; % 7362497;
dE00 = zeros(6, n,"single");
lab_NF = rand(6, 3, 'single');
labDB = rand(n, 3, 'single');
tic
for nClrs = 1:n
dE00(1:6, nClrs) = deltaE2000(lab_NF(1:6, 1:3), labDB(nClrs, 1:3));
end
toc
Elapsed time is 1.013390 seconds.
% Faster without explicit indexing:
tic
for nClrs = 1:n
dE00(:, nClrs) = deltaE2000(lab_NF, labDB(nClrs, :));
end
toc
Elapsed time is 0.722065 seconds.

1 Commento

Aiman Raza
Aiman Raza il 17 Nov 2022
Modificato: Aiman Raza il 17 Nov 2022
Thanks a lot! Removing the indexing did reduce the time to 106s. It is still better than before. I will try to code without a loop. That might further improve the timing.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 16 Nov 2022

Commentato:

il 17 Nov 2022

Community Treasure Hunt

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

Start Hunting!

Translated by