Hello,
On 10/24/12 13:57, gmail-unlp wrote:
>
> Hmmm... this (errors when using only one OpenMP thread) usually leads
> me to find some uninitialized/copied in thread local data. I'm trying
> to "reconstruct" the subroutine (I'm assuming
> a subroutine, but it could be a function, I think):
Well a test with four threads fails as well.
[post-composition preface: What follows is a looooong synopsis of where
we're at. So, if you're still inclined to keep reading, grab a coffee
and get comfy]
BTW, responding to other posts as well, here is the actual subroutine
statement:
SUBROUTINE POLATES6(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
along with all of the declarations:
IMPLICIT NONE
C
INTEGER, INTENT(IN ) :: IBI(KM), IPOPT(20), KM, MI, MO
INTEGER, INTENT(IN ) :: KGDSI(200), KGDSO(200)
INTEGER, INTENT( OUT) :: IBO(KM), IRET, NO
C
LOGICAL*1, INTENT(IN ) :: LI(MI,KM)
LOGICAL*1, INTENT( OUT) :: LO(MO,KM)
C
REAL, INTENT(IN ) :: GI(MI,KM)
REAL, INTENT( OUT) :: GO(MO,KM), RLAT(MO), RLON(MO)
C
REAL, PARAMETER :: FILL=-9999.
C
INTEGER :: IB, I1, IJKGDS1, IJKGDSA(20)
INTEGER :: JB, J1, K, LB, LSW, MP, N
INTEGER :: N11(MO), NB, NB1, NB2, NB3, NB4, NV
C
REAL, ALLOCATABLE :: CROT(:),SROT(:),WO(:,:)
REAL :: PMP,RLOB(MO),RLAB(MO)
REAL :: WB, XI, YI
REAL :: XPTB(MO),YPTB(MO),XPTS(MO),YPTS(MO)
The stripping out of the (supposedly) offending routines from the
library gets us to the point where the entire library, now CONTAINed as
internal subprograms in the main test, works!
Argh.
We've switched our focus to how the routine is called. Last night I was
digging a little deeper into how users actually call these routines and
I saw:
Subroutine interp, with definitions,
integer*4 :: i1
integer :: ip, ipopt(20), output_kgds(200)
integer :: km, ibi, mi, iret, i, j
integer :: i_output, j_output, mo, no, ibo
logical*1, allocatable :: output_bitmap(:,:)
real, allocatable :: output_rlat(:,:), output_rlon(:,:)
real, allocatable :: output_data(:,:)
calls "ipolates" thusly:
km = 1 ! number of fields to interpolate
mi = i_input * j_input ! dimension of input grids
mo = i_output * j_output
allocate (output_rlat(i_output,j_output))
allocate (output_rlon(i_output,j_output))
allocate (output_data(i_output,j_output))
allocate (output_bitmap(i_output,j_output))
call ipolates(ip, ipopt, input_kgds, output_kgds, mi, mo,&
km, ibi, input_bitmap, input_data, &
no, output_rlat, output_rlon, ibo, &
output_bitmap, output_data, iret)
And subroutine ipolates,
SUBROUTINE IPOLATES(IP,IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
IMPLICIT NONE
C
INTEGER, INTENT(IN ) :: IP, IPOPT(20), KM, MI, MO
INTEGER, INTENT(IN ) :: IBI(KM), KGDSI(200), KGDSO(200)
INTEGER, INTENT(INOUT) :: NO
INTEGER, INTENT( OUT) :: IRET, IBO(KM)
C
LOGICAL*1, INTENT(IN ) :: LI(MI,KM)
LOGICAL*1, INTENT( OUT) :: LO(MO,KM)
C
REAL, INTENT(IN ) :: GI(MI,KM)
REAL, INTENT(INOUT) :: RLAT(MO),RLON(MO)
REAL, INTENT( OUT) :: GO(MO,KM)
C
INTEGER :: K, N
calls the various "polatesX" routines like so
C NEIGHBOR-BUDGET INTERPOLATION
ELSEIF(IP.EQ.6) THEN
CALL POLATES6(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
So the "ipolates" driver routine has arguments dimensioned just like the
"polates6" routine.
The calling subroutine has, for some of the arrays, quite different
dimension sizes, but the same rank and total number of elements.
The big question I have now is regarding the IBI dummy argument - it is
declared as IBI(KM) in the library codes. In our test, KM is set to one.
In the main test driver (interp), ibi is declared as a scalar.
(I think wasn't picked up by the ifort interface-block-generation switch
because it's the *test* driver, not a library member. Argh.)
So, after reading Louis Krupp's post, I decided to try the combination
of "-O3 + -g" do get a debugger friendly failing results. And it worked!
Nobody had tried that before I guess assuming -O3 meant no -g. Anyhoo...
Inspecting the failure in the debugger shows that the IPOLATES
subroutine dummy argument values beyond the IBI argument are corrupted!
I'd *never* seen code before where an actual argument dimensioned
argument(N_I, N_J)
was passed in to a routine that was expecting
argument(N_I*N_J, 1)
Uff da.
So now we're dimensioning everything consistently to see if that is the
cause of the segfaulting.
There is a wrinkle in that the main IPOLATES calls are
C BILINEAR INTERPOLATION
IF(IP.EQ.0) THEN
CALL POLATES0(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C BICUBIC INTERPOLATION
ELSEIF(IP.EQ.1) THEN
CALL POLATES1(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C NEIGHBOR INTERPOLATION
ELSEIF(IP.EQ.2) THEN
CALL POLATES2(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C BUDGET INTERPOLATION
ELSEIF(IP.EQ.3) THEN
CALL POLATES3(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C SPECTRAL INTERPOLATION
ELSEIF(IP.EQ.4) THEN
CALL POLATES4(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C NEIGHBOR-BUDGET INTERPOLATION
ELSEIF(IP.EQ.6) THEN
CALL POLATES6(IPOPT,KGDSI,KGDSO,MI,MO,KM,IBI,LI,GI,
& NO,RLAT,RLON,IBO,LO,GO,IRET)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C UNRECOGNIZED INTERPOLATION METHOD
ELSE
....handle invalid method...
and:
a) the arguments are all dimensioned and called in the same weird way
b) only the call to POLATES6 segfaults. 0-4 complete normally.
Seeing as this is mostly f77-era, external subroutine code, is that type
of weird argument dimensioning illegal?
I am also told, after expressing horror at the argument dimensioning
shenanigans, that this "trick" is used in innumerable places in various
peoples codes. The same codes that ran apparently fine for years
(decades?) on IBM systems.
So, there you go. A comprehensive update of where we're at.
Any info about the legality of the dimensioning would be appreciated.
And, again, thanks to all who replied. Just getting other people's ideas
made a big difference.
cheers,
paulv