Tuesday, December 02, 2008

Less memory comsumption by est_noise6ac.

By default, est_noise6ac will take up about 1.8GB RAM to run. Although RAM is very cheap; however, not everyone had upgraded their hardware configuration. Fortunately, the memory usage can be greatly cut by small modifications to the raw source code.

The below is the original variables declaration:
character*3 net,instname(30),netx
character*132 string,filename
character*8 bsta(82), line(82), header(9)
character*1 ans
integer instnum(30),insol(30),intot(30),infunc(30)
integer instart(30),instop(30)
real inparam(30,10)
character*7 choice(10),exp_choice(10),exp_type(10)
dimension ran1(65536),ran2(65536),ran3(65536),ran4(65536)
double precision t_start,t_stop,rat_chg1(82),per(82),off(82),
& dest(82),timex,t_year(8103),texp(10),tpress,dtime(8103),
& dtime_orig(8103),rat_chg2(82), dec_timed,fjul,fjul1,fjul2,
& t(8103),rat_chng_norm(82)
dimension az(82),rc(20),d(8103),A(8103,82)
dimension d_orig(8103),A_orig(8103,82),t_orig(8103)
dimension res(8103),covinv(8103,8103),covar(8103,8103),x(82),
& e(82),dith(7),xx(7),bexp(10)
dimension ambp(8,7),amby(8),acov(8,8),cov(8,8),wz(23)
dimension vsig(8),vamp1(8),vexp1(8),vamp_bp(8),valpha(8),vamp2(8),
& vexp2(8)
dimension covarpl1(8103,8103),covarpl2(8103,8103),
& covarbp(8103,8103)
dimension press(8103),aux_norm(82)


Note that, the default size for most arrays is 8103. This threshold has exceeded the observation length of most CGPS site around the globe. For example, the site WUHN (1996.0697 - 2008.8374), a value of 5000 is suffice. Thus, we can modify the source to as follows:
integer*4 maxn
c parameter(maxn=3999)
parameter(maxn=5000)
character*3 net,instname(30),netx
character*132 string,filename
character*8 bsta(82), line(82), header(9)
character*1 ans
integer instnum(30),insol(30),intot(30),infunc(30)
integer instart(30),instop(30)
real inparam(30,10)
character*7 choice(10),exp_choice(10),exp_type(10)
dimension ran1(65536),ran2(65536),ran3(65536),ran4(65536)
double precision t_start,t_stop,rat_chg1(82),per(82),off(82),
& dest(82),timex,t_year(maxn),texp(10),tpress,dtime(maxn),
& dtime_orig(maxn),rat_chg2(82), dec_timed,fjul,fjul1,fjul2,
& t(maxn),rat_chng_norm(82)
dimension az(82),rc(20),d(maxn),A(maxn,82)
dimension d_orig(maxn),A_orig(maxn,82),t_orig(maxn)
dimension res(maxn),covinv(maxn,maxn),covar(maxn,maxn),x(82),
& e(82),dith(7),xx(7),bexp(10)
dimension ambp(8,7),amby(8),acov(8,8),cov(8,8),wz(23)
dimension vsig(8),vamp1(8),vexp1(8),vamp_bp(8),valpha(8),vamp2(8),
& vexp2(8)
dimension covarpl1(maxn,maxn),covarpl2(maxn,maxn),
& covarbp(maxn,maxn)
dimension press(maxn),aux_norm(82)

This will reduce the memory required to run est_noise from 1.8GB to about 632MB.

Warning: if you want to process sites with a long history, say from 1992 to present, you may need to set the threshold (maxn) larger.

1 comment:

Enod said...

Make the change to another function funmin. Ohterwise, the program may fail to get a solution and produce the errors like the below.


list of trial covariance parameters
white noise PL_1 amp PL_1 exp GM freq BP amp PL_2 amp PL_2 exp determinant chi^2 MLE cpu
covariance is singular
replace amplitude of noise, 1.00000 by 0.780000
covariance is singular
replace amplitude of noise, 0.780000 by 0.608400
covariance is singular