Re: WRAPIT functions

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu May 01 2014 - 13:33:30 MDT

I did not read the post carefully enough.

Somehow, I thought you were going to operate on the time
series at each level and lat/lon grid point.
If you are operating on one value, the absolute
worst thing you can do in terms of eficiency is to have
the innermost loop stride over the slowest varying dimension

In you NCL code the slowest varying dimension is the leftmost dimension.
The following would be faster in NCL (if the array 'x' is large)

   do k = 0, dimsizes(time)-1
     do l = 0, dimsizes(lev)-1
       do i = 0, dimsizes(lat)-1
         do j = 0, dimsizes(lon)-1 ; fastest varying dimension
                   FORTRAN WRAPIT object
           end do
       end do
     end do
   end do

===
  You should do the same for the fortran code.
  In fortran, the fastest varying dimension is the left.

===
Always make the innermost loop stride over the fastest
varying dimension.

On 5/1/14, 1:11 PM, Dennis Shea wrote:
> Do the looping in the fortran.
>
> Consider an NCL ordered array x(ntim,klev,nlat,mlon)
>
> In fortran, that *same* array is x(mlon,nlat,klev,ntim)
>
> (In memory, the array is stored linearly with the fastest
> varying dimensions mapping into one another.)
>
> An f77 version might look like
>
> C NCLFORTSTART
> subroutine driver(x,ntim,klev,nlat,mlon, result)
> implicit none
> c INPUT
> integer ntim,klev,nlat,mlon
> real x(mlon,nlat,klev,ntim)
> c OUTPUT
> real result(......)
> C NCLEND
> c LOCAL (dynamic allocation)
> integer nt,kl,nl,ml
> real work(ntim)
>
>
> do nl=1,nlat
> do ml=1,mlon
> do kl=1,klev
>
> do nt=1,ntim
> work(nt) = x(ml,nl,kl,nt)
> end do
> call foo(work,ntim, result,...)
> end do
> end do
> end do
>
> return
> end
>
>
> ===
> external JBUZAN "./...so"
>
> result = new ( (/.../),typeof(x),getFillValue(x))
>
> JBUZAN::driver(xntim,klev,nlat,mlon, result)
>
> On 5/1/14, 12:13 PM, jbuzan wrote:
>> Hello NCL-Talk.
>>
>> My fortran code that I am using only works on single cells. I am wondering if there is a more efficient way for me to set up my loops.
>>
>> Input dataset is netcdf files (atmospheric output):
>> X(time,lev,lat,lon).
>>
>> loop construction:
>>
>> do i = 0, dimsizes(lat)-1
>> do j = 0, dimsizes(lon)-1
>> do l = 0, dimsizes(lev)-1
>> do k = 0, dimsizes(time)-1
>> FORTRAN WRAPIT object
>> end do
>> end do
>> end do
>> end do
>>
>> Thanks,
>>
>> -Jonathan
>> _______________________________________________
>> 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 Thu May 01 13:33:37 2014

This archive was generated by hypermail 2.1.8 : Sun May 04 2014 - 12:38:56 MDT