Re: memory leak when using png driver?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Sat Feb 06 2010 - 10:33:40 MST

As Rick suggested, it's a good idea to move code outside a do loop as
much as possible. You are constructing "name" and "name1" inside the
loop, and this can be done outside the loop using "ispan":

ii = ispan(0,364*4,1)
name = "/scratch60d/csmith/20th/prcpx." + sprinti("%4.4i", ii+1)

Be sure to change all "name" references inside your loop to "name(id)".

In addition, you might try deleting the "wks" variable at the end of
the loop. This will force your PNG file to be closed:

delete(wks)

I think Rick is being modest, but he has implemented an interface to a
cairo PNG driver that will hopefully render this old PNG driver
obsolete.

We'd like to have some testers for this feature (mainly because I'm
worried about library dependencies and not the code itself).

Email me and Rick offline if you'd like to try a beta version of 5.2.0
with the new PNG driver. I will need to know what "uname -a" and
"gfortran --version" reports on your system.

Thanks,

--Mary

On Feb 5, 2010, at 4:29 PM, Rick Brownrigg wrote:

> Hi Cathy,
>
> I'm not totally sure about a memory leak offhand, but I might suggest
> that you pull the code that sets up resources and opens the
> workstation to outside of your loop-through-days.
>
> Hope that helps...
> Rick
>
> On Feb 5, 2010, at 4:23 PM, Cathy Smith wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> NCL users,
>>
>> I have code that loops through a file to create a set of maps for a
>> year. I open the file and get the variable plotted before the loop to
>> plot the maps.
>>
>> e.g.
>>
>> read data
>>
>> do loop though days
>> wks_type = "png"
>> rez=2560
>> output="png"
>> temp = pr_wtr(day,:,:)
>> wks = gsn_open_wks(output,name) ; open a png file
>> gsn_define_colormap(wks,"prwtr") ; choose colormap
>> ...set plot parameters...
>> plot=gsn_csm_contour_map_ce(wks,temp,res)
>>
>> end do
>>
>> The problem is that the code isn't releasing memory and it starts
>> taking
>> over all the memory in the machine (30G!). Is there a way to release
>> the
>> memory? Or, do I likely have an error somewhere? We are using NCL
>> 5.1.1
>> on a 64 bit Linux redhat machine (V 2.6.18-164.6.1.el5)
>>
>> Thanks
>> Cathy Smith
>>
>>
>>
>>
>> (short code that produces error)
>>
>> ;************************************************
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>
>> ;************************************************
>> begin
>>
>> ;************************************************
>> ; read in netCDF file
>> ;************************************************
>> a = addfile("/Datasets/20thC_ReanV2/monolevel/pr_wtr.eatm.
>> 1902.nc","r")
>> pr_wtr = short2flt( a->pr_wtr )
>>
>> do id=0,364*4
>> nd=id+1
>> temp = pr_wtr(id,:,:)
>> name1=sprinti("%4.4i", nd)
>> name="/scratch60d/csmith/20th/prcpx." + name1
>> print(name)
>> rez=2560
>> output="png"
>> output@wkWidth = rez ; must be square; deviations
>> output@wkHeight = rez ; either way are
>> wasted
>> wks = gsn_open_wks(output,name) ; open a png file
>> gsn_define_colormap(wks,"prwtr") ; choose colormap
>>
>> res = True
>> res@cnFillOn = True ; turn on color fill
>> res@gsnSpreadColors = True ; use full range of color map
>> res@mpMinLonF=0
>> res@mpMaxLonF=360
>> res@gsnAddCyclic=True
>> res@mpMinLatF = -90
>> res@mpMaxLatF = 90
>>
>> plot=gsn_csm_contour_map_ce(wks,temp,res) ; now draw as
>> one plot
>>
>> end do
>> end
>>
>> )
>>
>>
>> - --
>> NOAA/ESRL PSD and CIRES CDC
>> 303-497-6263
>> http://www.esrl.noaa.gov/psd/people/cathy.smith/
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.9 (Darwin)
>>
>> iEYEARECAAYFAktsqF4ACgkQFiO7KzMhjUST4gCfWqAgknO2by0/Qpz7zoSIbw4/
>> yAUAn3hq+7TbH7okBqUW1QjSGkko04G6
>> =LNms
>> -----END PGP SIGNATURE-----
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Feb 6 10:33:45 2010

This archive was generated by hypermail 2.1.8 : Sun Feb 07 2010 - 15:37:25 MST