Hi,
I am trying to run a 3d for loop, which is taking 3 hrs to run. I tried some of the best practices for loops such as pre-allocating the array, indexing and parfor but it does not improve the processing time. Please can you suggest to improve the execution time.
for i1= 1:length(RGI_glacier_temp_C_avg) % length of 216
for j1 = 1:length(elev_bins) % array size 200
for k1 = 1:length(gl_max_elev) % array size 18,000
RGI_downscld_no_thre(i1,j1,k1) = temp2m_all_grids_avg(i1,:) + lr_era * (elev_bins(:,j1) - gl_max_elev(k1,:));
RGI_downscld_no_thre_C(i1,j1,k1) = temp2m_all_grids_C_avg(i1,:) + lr_era * (elev_bins(:,j1) - gl_max_elev(k1,:));
end
end
end

 採用された回答

Bruno Luong
Bruno Luong 2022 年 8 月 24 日
編集済み: Bruno Luong 2022 年 8 月 25 日

0 投票

Try this:
T = reshape(temp2m_all_grids_avg, [], 1, 1);
Tc = reshape(temp2m_all_grids_C_avg, [], 1, 1);
hbins = reshape(elev_bins,1,[],1);
maxh = reshape(gl_max_elev,1,1,[]);
Th = lr_era * (hbins - maxh);
RGI_downscld_no_thre = T + Th;
RGI_downscld_no_thre_C = Tc + Th;
These outputs require more than 10 Gb on RAM. You might compute the array in single if you run out of memory or it starts to swap on HD.

1 件のコメント

Lavanya Ashokkumar
Lavanya Ashokkumar 2022 年 8 月 24 日
Thank you very much. It worked.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by