Re: execution time issue

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Jul 08 2010 - 16:36:06 MDT

Sahidul,

One problem is that you have three nested do loops, and you have code inside your do loops that is doing the same thing every time.

It's important with *any* scripting language to keep your do loops clean, and move any code that doesn't change outside the do loop.

For example, you are setting a bunch of resources inside the do loop. Move these outside.

You have a bunch of "if(pressure.eq.xxxx)" type statements that can be consolidated into one statement.

I've included a modified version of your script below. This may not run much faster, because with three do loops, you are going to have issues.
It may be possible that you don't need to open a new file every time inside the do loop. Perhaps you can use "addfiles" instead of "addfile".

Before looking at that, though, try the new script and see if there's any improvement:

;;***************************************************
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/wrf/WRFUserARW.ncl"
begin

;; in this directory, I have 87 wrfout files ( every 1 hour interval file)

datadir = "/WRF_output/2010062200/"
FILES = systemfunc ("ls -1 " + datadir + "wrfout_d02* " )
numFILES = dimsizes(FILES)

res = True
res@InitTime = False
res@Footer = False

plevs = (/ 1000., 925., 850., 700., 600., 500., 300., 200. /)
nlevels = dimsizes(plevs)

res = True ; Plot options desired.
res@gsnDraw = True ; Forces the plot to be drawn
res@gsnFrame = True ; Frame advance
pltres = True
mpres = True

opts = res
opts@cnFillOn = True
opts@cnInfoLabelOn = False

mpres@mpNationalLineThicknessF = 1.0
mpres@mpNationalLineColor = "black"
mpres@mpGeophysicalLineColor = "black"
mpres@mpGeophysicalLineThicknessF = 1.0

do ifil = 0,numFILES-1
   a = addfile(FILES(ifil)+".nc","r")

    times = wrf_user_list_times(a)
    ntimes = dimsizes(times)

do it = 0,ntimes-1,2
;;;===========================
yr = systemfunc("echo "+times +"|cut -c1-4")
mon = systemfunc("date '+%b'|tr [a-z] [A-Z]")
day = systemfunc("echo "+times +"|cut -c9-10")
hr = systemfunc("echo "+times +"|cut -c12-13")
;;;===========================
     w = wrf_user_getvar(a,"wa",it)
 do level = 0,nlevels-1

   pressure =plevs(level)
   p = wrf_user_getvar(a, "pressure",it)
   w_plane = wrf_user_intrp3d(w,p,"h",pressure,0.,False)
   w_plane@description = ""
   w_plane@units = ""

  wks = gsn_open_wks("ps","om_"+pressure+"hPa"+"_"+day+mon+yr+"_"+hr+"Z")

 vector_w = wrf_contour(a,wks,w_plane,opts)
 plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)

        if ( any(pressure.eq.plevs).and.pressure.ne.1000. ) then
            plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
        end if
end do
end do
end do
end
;;***************************************************

On Jul 8, 2010, at 4:37 AM, Sahidul wrote:

> Dear NCL Users,
>
> Following script is working fine. BUT It is taking lot of time ( more than 6 hours) to complete.
>
> Could you please suggest me how to run it fast.
>
> ;;***************************************************
> 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/wrf/WRFUserARW.ncl"
> begin
>
> ;; in this directory, I have 87 wrfout files ( every 1 hour interval file)
>
> datadir = "/WRF_output/2010062200/"
> FILES = systemfunc ("ls -1 " + datadir + "wrfout_d02* " )
> numFILES = dimsizes(FILES)
>
> res = True
> res@InitTime = False
> res@Footer = False
>
> do ifil = 0,numFILES-1
> a = addfile(FILES(ifil)+".nc","r")
>
> times = wrf_user_list_times(a)
> ntimes = dimsizes(times)
> plevs = (/ 1000., 925., 850., 700., 600., 500., 300., 200. /)
> nlevels = dimsizes(plevs)
>
> do it = 0,ntimes-1,2
> ;;;===========================
> yr = systemfunc("echo "+times +"|cut -c1-4")
> mon = systemfunc("date '+%b'|tr [a-z] [A-Z]")
> day = systemfunc("echo "+times +"|cut -c9-10")
> hr = systemfunc("echo "+times +"|cut -c12-13")
> ;;;===========================
> w = wrf_user_getvar(a,"wa",it)
> do level = 0,nlevels-1
>
> pressure =plevs(level)
> p = wrf_user_getvar(a, "pressure",it)
> w_plane = wrf_user_intrp3d(w,p,"h",pressure,0.,False)
> w_plane@description = ""
> w_plane@units = ""
>
> wks = gsn_open_wks("ps","om_"+pressure+"hPa"+"_"+day+mon+yr+"_"+hr+"Z")
>
> res = True ; Plot options desired.
> res@gsnDraw = True ; Forces the plot to be drawn
> res@gsnFrame = True ; Frame advance
> pltres = True
> mpres = True
>
> opts = res
> opts@cnFillOn = True
> opts@cnInfoLabelOn = False
>
> mpres@mpNationalLineThicknessF = 1.0
> mpres@mpNationalLineColor = "black"
> mpres@mpGeophysicalLineColor = "black"
> mpres@mpGeophysicalLineThicknessF = 1.0
>
> vector_w = wrf_contour(a,wks,w_plane,opts)
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
>
> if ( pressure .eq. 925 ) then
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
> end if
> if ( pressure .eq. 850 ) then
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
> end if
> if ( pressure .eq. 700 ) then
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
> end if
> if ( pressure .eq. 600 ) then
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
> end if
> if ( pressure .eq. 500 ) then
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
> end if
> if ( pressure .eq. 300 ) then
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
> end if
> if ( pressure .eq. 200 ) then
> plot = wrf_map_overlays(a,wks,vector_w,pltres,mpres)
> end if
>
> end do
> end do
> end do
> end
> ;;***************************************************
>
> Kindly help me.
>
> Thanking you,
>
> _______________________________________________
> 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 Thu Jul 8 16:36:13 2010

This archive was generated by hypermail 2.1.8 : Fri Jul 09 2010 - 16:06:21 MDT