<div dir="ltr">Deleting "dat", which is your file pointer, does exactly what it should do - deletes the variable that points to your file. This is, at most, a few dozen bytes. Compared to entire globes worth of temperature data for 30 years, we're talking 10 orders of magnitude too small to make a difference. The only way to reduce your memory usage is to *read less data* - there is no other way to speed this up, unless you have another machine. This is not an issue with NCL, but rather with how you are designing your code. As the scientist here, it is up to YOU to figure out how much data you have, know if your machine can handle it, and try and determine the best way to process it on your way to performing your analysis. Unless you are performing a function that uses all 30 years of data at once, I would suggest reading in the files one at a time (monthly it appears?) and performing your calculations on that, then writing/plotting the output as you go. This should make things much faster. If you do need all 30 years of data at once, consider how you need it. Maybe you plan on spatially averaging the data into daily points? If so, you can do that as you read it in.<div><br></div><div>Basically, try and reduce the amount of unnecessary data that is sitting around at any one point in time.</div></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr">----------------------------------------<div>Kyle S. Griffin</div><div>Department of Atmospheric and Oceanic Sciences</div><div>University of Wisconsin - Madison</div><div>Room 1421</div><div>1225 W Dayton St, Madison, WI 53706</div><div>Email: <a href="mailto:ksgriffin2@wisc.edu" target="_blank">ksgriffin2@wisc.edu</a></div></div></div>
<br><div class="gmail_quote">On Fri, Sep 12, 2014 at 5:19 PM, <span dir="ltr"><<a href="mailto:rupingmo@gmail.com" target="_blank">rupingmo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u><div>Hi Jon,<br><br>I do have the latest version of NCL (v6.2.1). The code is running fast to the point where the previous run was terminated, then begins to slow down. The delete function (in my case, delete(dat)) at the end of each iteration doesn't seem to help.<br><br>Ruping<div>Sent from my BlackBerry device on the Rogers Wireless Network</div><hr><div><b>From: </b> Jon Meyer <<a href="mailto:jonathan.meyer@aggiemail.usu.edu" target="_blank">jonathan.meyer@aggiemail.usu.edu</a>>
</div><div><b>Date: </b>Fri, 12 Sep 2014 16:03:19 -0600</div><div><b>To: </b>Ruping Mo<<a href="mailto:rupingmo@gmail.com" target="_blank">rupingmo@gmail.com</a>>; <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>></div><div><b>Subject: </b>Re: [ncl-talk] The slow down when addfile is used in do loop</div><div><div class="h5"><div><br></div><div dir="ltr">What version of NCL are you using? Version 6.2 fixed a minor memory leak associated when .grb files are opened. When numerous .grb files are opened sequentially, the small memory leak can cause your memory footprint to grow with time...even if you are using the 'delete' function after each loop iteration.<div><br></div><div>If your code is running fast at first, using the delete function at the end of each iteration will likely solve your issue.<br><div><br></div><div>Jon</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 12, 2014 at 2:31 PM, Ruping Mo <span dir="ltr"><<a href="mailto:rupingmo@gmail.com" target="_blank">rupingmo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi NCLers,</div><div><br></div><div>I have an archive of large grib files. Each grib file contains a month of multiple daily global variables. I use the following script to extract a small part of one variable. The script, which uses addfile in a large loop, runs very fast for the first few months, then begins to slow down substantially. I let it run for a few years, then terminate the job (Ctrl-Z) and re-run the same script. Surprisingly, the new job runs very fast to the month when the previous job was terminated. I wonder why it behaves this way, and what I can do to avoid the slow down problem.</div><div><br></div><div>Have a nice day!</div><div><br></div><div>Ruping</div><div><br></div><div>The script:</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div>begin</div><div> nday = 12784 ; number of days from Jan 1979 to Dec 2013</div><div> temp = new((/nday, 9, 9/), float)</div><div>;;;;</div><div> t0 = 0</div><div> do yr = 1979, 2013</div><div> syr = tostring(yr)</div><div> do mo = 1, 12</div><div> smo = tostring(mo)</div><div> print(syr + "-" + smo)</div><div> fname = syr + "/" + syr + "-" + smo + ".grib"</div><div> dat = addfile(fname, "r")</div><div> mday = getfilevardimsizes(dat, "initial_time0") - 1</div><div> i1 = i0 + mday</div><div> temp(i0:i1, :, :) = (/ dat->2T_GDS0_SFC(:, 80:88, 146:154) /)</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2T_GDS0_SFC(mday, 241, 480)</div><div> i0 = i1 + 1</div><div> end do</div><div> end do</div><div>end</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div></div>
<br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</div></div></div><br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>