[ncl-talk] NCL memory leak issue
    STEFAN RAHIMI-ESFARJANI 
    s.rahimi at ucla.edu
       
    Thu Oct  8 09:24:06 MDT 2020
    
    
  
Greetings,
I spent a lot of time developing post-processing software for my research,
which are written in NCL. The code here creates single-year files of
daily evapotranspiration values on a lat/lon grid f(time,lat,lon). I am
experiencing a memory leak that is affecting my ability to run these jobs
using Cheyenne compute nodes.
In short, I have traced the memory leak to the following line (70) in
/glade/scratch/srahimi/interp/mpi_r8/test.ncl on Cheyenne or see below:
ff = addfiles(dir_x+files,"r")
The files are wrfout .nc files. Variable "ff" should be deleted 2 lines
later, and that space should be re-used throughout each iteration of the
loop. What seems to be happening however is that new memory is being
allocated for ff in each iteration of the loop, eventually overpowering the
core and the node.
I know ways around this in python, but I really do not want to rewrite
these scripts at present. Any suggestions?
Thanks,
-Stefan Rahimi, UCLA
;Created by S. Rahimi on 15 Jan. 2020
;to interpolate WRF fields toa common
;0.03 rectilinear grid
;Daily averages from 6-h data
;For a 2-D variable
;f = f(year,day,ny,nx)
begin
var = "etrans_sfc"
model  = "mpi-esm1-2-lr"
variant  = "r8i1p1f1"
ssp  = "ssp370"
freq = "daily"
domain  = "d01"
startyear  = 1980
endyear  = 1989
year0 = 1980
dir  = "/glade/scratch/srahimi/ucla/downscale/test/WRF-4.1.3/test/"
dir_inp  = "/glade/scratch/srahimi/interp/meta2/"
file_wrfinput  = "/glade/scratch/srahimi/interp/meta2/wrfinput_d01"
s2d = 86400.
ndays = 365
nyears = endyear - startyear + 1
nx  = 109
ny  = 104
;lat/lon from wrfinput
print (file_wrfinput+"")
f = addfile(file_wrfinput,"r")
lat_wrf = f->XLAT(0,:,:)
lon_wrf = f->XLONG(0,:,:)
delete(f)
years = ispan(startyear,endyear,1)
days = new((/ndays/),"integer")
var_wrf = new((/ndays,ny,nx/),"float")
do iyear = startyear, endyear
if (iyear .eq. 2014 ) then
        continue
end if
 dir_x =  dir + "MPI_r8_" + iyear + "/" + domain + "/"
 print (dir_x+"")
 file_str = "wrfout*"
 filei = systemfunc("cd " + dir_x + " ; ls " + file_str)
 day_count = 1
 do iday = 0, ndays - 1
  files = filei(4*(day_count-1):4*day_count-1)
  print (files) ;each is a string
  date_str = stringtochar(files(0))
  date = tostring(date_str(11:14)) + tostring(date_str(16:17)) +
tostring(date_str(19:20))
  days(iday) = stringtointeger(date)
  ff = addfiles(dir_x+files,"r")
  var_wrf(iday,:,:) =  dim_avg_n_Wrap(ff[0:dimsizes(files)-1]->ETRAN,0) *
s2d
  delete(ff)
  var_wrf(iday,:,:) = where(abs(var_wrf(iday,:,:)).gt.1e20,0.,
var_wrf(iday,:,:))
  day_count = day_count + 1
  delete(files)
 end do         ;end day loop
 var_wrf!0 = "day"
 var_wrf!1 = "lat2d"
 var_wrf!2 = "lon2d"
 var_wrf&day = days
 var_wrf at units = "mm/d"
 ;Write to .nc files
 dirout = "files/"
 fil_out = var + "." + freq + "." + \
  model + "_" + ssp + "_" + variant + "_" + \
  domain + "_" + iyear + ".nc"
 outfile = dirout+fil_out
 system("/bin/rm " +outfile)
 ncdf = addfile(outfile ,"c")  ; open output netCDF file
 ;setfileoption(outfile,"DefineMode",True)
 fAtt               = True            ; assign file attributes
 fAtt at title         = var+ " for  "+iyear
 fAtt at Conventions   = "None"
 fAtt at creation_date = systemfunc("date")
 ;fileattdef(ncdf,f[0])            ; copy file attributes
 filedimdef(ncdf,"region",-1,True)
 ncdf->$var$ = var_wrf
 delete(ncdf)
end do          ;end year loop
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201008/1068032c/attachment.html>
    
    
More information about the ncl-talk
mailing list