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 件のコメント

DGM
DGM 2022 年 11 月 16 日
編集済み: DGM 2022 年 11 月 16 日
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?
Aiman Raza
Aiman Raza 2022 年 11 月 17 日
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 !
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
編集済み: Bruno Luong 2022 年 11 月 17 日
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.
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
編集済み: Bruno Luong 2022 年 11 月 17 日
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)
Aiman Raza
Aiman Raza 2022 年 11 月 17 日
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?
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
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.
Aiman Raza
Aiman Raza 2022 年 11 月 17 日
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?
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
I don't want to answer speeding up your code here. It's off topic.
Aiman Raza
Aiman Raza 2022 年 11 月 17 日
Thanks for your help though, it makes more sense to why my code suddenly runs slower. Have a great day!
Star Strider
Star Strider 2022 年 11 月 17 日
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.
.
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
編集済み: Bruno Luong 2022 年 11 月 17 日
@Star Strider can you please run the code (the one I posted) and post the result?
Aiman Raza
Aiman Raza 2022 年 11 月 17 日
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.
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
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 "
Aiman Raza
Aiman Raza 2022 年 11 月 17 日
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.
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
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.
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
編集済み: Bruno Luong 2022 年 11 月 17 日
I run gain the code on my Intel laptop
R2021a: 85 seconds
R2022b: 87 seconds
Aiman Raza
Aiman Raza 2022 年 11 月 17 日
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.

サインインしてコメントする。

 採用された回答

Jan
Jan 2022 年 11 月 17 日

1 投票

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 件のコメント

Aiman Raza
Aiman Raza 2022 年 11 月 17 日
編集済み: Aiman Raza 2022 年 11 月 17 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProfile and Improve Performance についてさらに検索

タグ

質問済み:

2022 年 11 月 16 日

コメント済み:

2022 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by