Re: WRAPIT functions

From: jbuzan <jbuzan_at_nyahnyahspammersnyahnyah>
Date: Thu May 01 2014 - 15:12:19 MDT

Thanks, Dennis.
I should have been more clear that my loops were in NCL and that I was calling single point calculation FORTRAN.

-Jonathan

On May 1, 2014, at 3:33 PM, Dennis Shea <shea@ucar.edu> wrote:

> 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 15:12:35 2014

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