Re: About memory issues...

From: Andrew Dawson <dawson_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 06 2012 - 03:09:54 MDT

This is not a memory issue actually. The issue is that the random number
generator is being seeded with the same number each time the script is run.
To change this you just need to call the random_setallseed function with a
different value each time you run the script. The typical method to do this
is to use the current time as the seed.

Try adding the following two lines before your loop:

time = tointeger(systemfunc("date +%s"))
random_setallseed(time, time)

This will seed the generator used by random_uniform with a value that is
dependent on the current time. Hope that helps.

Andrew

On 6 August 2012 05:02, Victor Torres <vtpuente@gmail.com> wrote:

> Hi there!
> I'm using the function random_uniform inside a do loop, however
> when I execute it a second, third and n - time it always returns the
> same values, here it is the script and the results:
>
>
> ;*******************************************************************************************************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> begin
> do i = 1, 5
> X = (/-2.41, 4.86, 6.06, 9.11, 10.2, 12.81, 13.17, 14.1, 15.77, 15.79/)
> a = round(random_uniform(0,dimsizes(X)-1,dimsizes(X)),3)
> print(a)
> delete(a)
> end do
>
> end
>
> ;********************************************************************************************************
>
> The results are:
>
> victor@orange:~/Desktop/pre$ ncl randum.ncl
> Copyright (C) 1995-2011 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.0.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 3
> (1) 3
> (2) 4
> (3) 3
> (4) 3
> (5) 1
> (6) 5
> (7) 7
> (8) 3
> (9) 3
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 8
> (1) 3
> (2) 3
> (3) 5
> (4) 7
> (5) 0
> (6) 0
> (7) 3
> (8) 1
> (9) 7
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 3
> (1) 2
> (2) 1
> (3) 1
> (4) 6
> (5) 4
> (6) 7
> (7) 6
> (8) 4
> (9) 8
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 4
> (1) 0
> (2) 8
> (3) 7
> (4) 3
> (5) 4
> (6) 7
> (7) 0
> (8) 1
> (9) 1
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 8
> (1) 3
> (2) 4
> (3) 7
> (4) 2
> (5) 7
> (6) 3
> (7) 8
> (8) 6
> (9) 4
> victor@orange:~/Desktop/pre$
> victor@orange:~/Desktop/pre$ ncl randum.ncl
> Copyright (C) 1995-2011 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.0.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 3
> (1) 3
> (2) 4
> (3) 3
> (4) 3
> (5) 1
> (6) 5
> (7) 7
> (8) 3
> (9) 3
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 8
> (1) 3
> (2) 3
> (3) 5
> (4) 7
> (5) 0
> (6) 0
> (7) 3
> (8) 1
> (9) 7
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 3
> (1) 2
> (2) 1
> (3) 1
> (4) 6
> (5) 4
> (6) 7
> (7) 6
> (8) 4
> (9) 8
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 4
> (1) 0
> (2) 8
> (3) 7
> (4) 3
> (5) 4
> (6) 7
> (7) 0
> (8) 1
> (9) 1
>
>
> Variable: a
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 8
> (1) 3
> (2) 4
> (3) 7
> (4) 2
> (5) 7
> (6) 3
> (7) 8
> (8) 6
> (9) 4
> victor@orange:~/Desktop/pre$
>
> And so on...
>
> It seems that the memory allocation is the same, does anybody knows
> how to clean this memory allocation from ncl???
>
> Thank you very much
> Regards
>
> Victor Torres
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
Dr Andrew Dawson
Atmospheric, Oceanic & Planetary Physics
Clarendon Laboratory
Parks Road
Oxford OX1 3PU, UK
Tel: +44 (0)1865 282438
Email: dawson@atm.ox.ac.uk
Web Site: http://www2.physics.ox.ac.uk/contacts/people/dawson

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Aug 6 03:10:07 2012

This archive was generated by hypermail 2.1.8 : Wed Aug 15 2012 - 08:12:08 MDT