<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hey Paolina,<div class="">first of all it would be nice to add a few print statement to understand which parts of the scripts are actually slowing it down.</div><div class="">Something like this:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">print("************************************************")</font></div><div class=""><font face="Menlo" class="">print("FILEs READ in "+get_cpu_time()+"s")</font></div><div class=""><font face="Menlo" class="">print("************************************************")</font></div></div><div class=""><br class=""></div><div class="">would help. </div><div class=""><br class=""></div><div class="">Second, taking a peek at your script it seems that the loop part is slowing everything down. That's not how you're supposed to compute quantities in NCL :) </div><div class="">Explicit loops over variable dimensions should be used ONLY when strictly necessary as they are slowing everything down. </div><div class=""><br class=""></div><div class="">For example, if you have a 3-D array including temperatures <font face="Menlo" class="">T(ntime,nlon,nlat) </font>in Kelvin and you want to convert them to Celsius the assignment</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">T=T-273.15 </font></div><div class=""><br class=""></div><div class="">has the same effect as</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">do i=0,ntime-1 </font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>do j=0,nlon-1</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>do k=0,nlat-1</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>T(i,j,k)=T(i,j,k)-273.15</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>end do </font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>end do </font></div><div class=""><font face="Menlo" class="">end do</font> </div><div class=""><br class=""></div><div class="">but takes less time (and effort to write it up). </div><div class=""><br class=""></div><div class="">In your case if you want to compute saturation vapor pressure I'd suggest you to use one of the function described here <a href="https://www.ncl.ucar.edu/Document/Functions/meteo.shtml" class="">https://www.ncl.ucar.edu/Document/Functions/meteo.shtml</a> on the full array of temperature and pressure, without subsetting them! </div><div class=""><br class=""></div><div class="">Furthermore, remember than in Fortran (and so also in NCL) the order of the internal loops does matter for speed. An excerpt from an EXCELLENT explanation from Dennis given a "long time ago"</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="text-align: left;" class=""><i style="font-family: Arial;" class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">Looping in *any* interpreted language (Matlab, python, NCL) is </span><span class="il" style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);">slow</span></i></div></div><div class=""><font face="Arial" class=""><div style="text-align: left;" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">compared to compiled languages. Interpreted languages execute one line</span></i></div></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">at a time. Functions within interpreted languages are written in C</span></i></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-variant-ligatures: normal;" class=""><font color="#222222" class=""><span style="font-size: 12.8px;" class="">and/or fortran. These are </span><span style="font-size: 12.800000190734863px;" class="">optimised</span><span style="font-size: 12.8px;" class=""> BUT the overall interpreted code</span></font></span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">is not. [...] </span></i><i style="font-size: 12.8px;" class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">The reason is that compiled languages, in particular, fortran (due the</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">the 'rules of the language') often have 'look ahead' information that</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">allow the language to issue pre-fetch instructions prior to a code</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">segment being executed. This allows the hardware to pre-load cache and</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">registers with data. This makes execution faster.</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><font color="#222222" class=""><span style="font-size: 12.800000190734863px;" class=""><br class=""></span></font></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span class="il" style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);"><div style="text-align: left;" class="">[...]</div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><font color="#222222" class=""><span style="font-size: 12.800000190734863px;" class=""><br class=""></span></font></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">This affects compiled languages also. A real world case. A post-doc</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">was calling a fortran code that had 4-levels. She said it was taking a</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">*long* time. I looked at the code</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><font color="#222222" class=""><span style="font-size: 12.800000190734863px;" class=""><br class=""></span></font></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> x(mlon,nlat,klev,ntim) , y(mlon,nlat,klev,ntim) </span></i><i style="font-size: 12.8px;" class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> ... fortran</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">ordering ... these were *BIG* arrays. in fortran the left is the</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">fastest varying dimension</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><font color="#222222" class=""><span style="font-size: 12.800000190734863px;" class=""><br class=""></span></font></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">She had</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><font color="#222222" class=""><span style="font-size: 12.800000190734863px;" class=""><br class=""></span></font></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> do kll=1,klev</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> do nl=1,nlat</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> do ml=1,mlon</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> do nt=1,ntim</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">....</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> end do</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> end do</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> end do</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""> end do</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><font color="#222222" class=""><span style="font-size: 12.800000190734863px;" class=""><br class=""></span></font></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">It took 20+ minutes</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><div style="text-align: left;" class=""><font color="#222222" class=""><span style="font-size: 12.800000190734863px;" class=""><br class=""></span></font></div></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">I looked at the code and saw nothing wrong. Later, I realized the</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">issue. She was striding over the slowest varying dimension.</span></i></div></span></i></font></div><div class=""><font face="Arial" class=""><i class=""><span style="color: rgb(34, 34, 34); font-size: 12.8px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><div style="text-align: left;" class=""><i class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">She reordered code ....</span></i><i style="font-size: 12.8px;" class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class="">It took about 45 seconds. Wow!</span></i></div><div style="text-align: left;" class=""><i style="font-size: 12.8px;" class=""><span style="font-size: 12.8px; font-variant-ligatures: normal;" class=""><br class=""></span></i></div></span></i></font></div></blockquote><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 19. Oct 2017, at 11:10, Paolina Bongioannini Cerlini <<a href="mailto:paolina.cerlini@unipg.it" class="">paolina.cerlini@unipg.it</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span id="cid:202C51C9-53B7-4F40-9C01-D5FA321F5C76@mpimet.mpg.de"><BM-256x256x64_3km_SWVP-new_0.ncl></span></div></blockquote></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">Guido Cioni</div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://guidocioni.altervista" class="">http://guidocioni.altervista</a>.org</div>
</div>
<br class=""></div></body></html>