unexpected runtime function call

Hi,

I’ve made alot of progress debugging my program, and I don’t have anymore (obvious) syntax errors. However, when the compiler gets through the file it gives me the error :

PGF90-F-0000-Internal compiler error. unexpected runtime function call 0 (rieman.F90: 621)
PGF90/x86-64 Linux 10.5-0: compilation aborted
gmake: *** [rieman.o] Error 2


my code is as follows

!!****if* source/physics/Hydro/HydroMain/split/PPM/PPMKernel/rieman
!!
!! NAME
!! 
!!  rieman
!!
!! SYNOPSIS
!!
!!       call rieman ( integer(IN) :: numIntCells, 
!!                     integer(IN) :: numCells, 
!!                     real(OUT)   :: rhoav(numCells), 
!!                     real(OUT)   :: uav(numCells), 
!!                     real(OUT)   :: utav(numCells), 
!!                     real(OUT)   :: uttav(numCells), 
!!                     real(OUT)   :: pav(numCells), 
!!                     real(OUT)   :: urell(numCells), 
!!                     real(IN)    :: ugrdl(numCells), 
!!                     real(IN)    :: game(numCells), 
!!                     real(OUT)   :: gameav(numCells), 
!!                     real(OUT)   :: xnav(numCells, hy_numXn), 
!!                     real(IN) :: x(numCells))
!!                 
!!
!!
!! DESCRIPTION
!!  
!!  Solve riemann shock tube problem for a general equation of state using 
!!  the method of Colella and Glaz.  Use a two shock approximation, and
!!  linearly interpolation between the head and tail of a rarefaction to
!!  treat rarefactions.
!!
!!  Take as input the effective left and right states, obtained by 
!!  integrating the parabolic reconstructions of the data over the domain
!!  of dependence of each of the characteristics on the respective side
!!  of the interface.  This is accomplished by states().  Return the
!!  solution to Riemann's problem on axis -- this is used in computing
!!  the fluxes.
!!
!!  The Riemann problem for the Euler's equation produces 4 states, 
!!  separated by the three characteristics (u - cs, u, u + cs):
!!
!!
!!        l_1      t    l_2       l_3
!!         \       ^   .       /
!!          \  *L  |   . *R   /
!!           \     |  .     /
!!            \    |  .    /
!!        L    \   | .   /    R
!!              \  | .  /
!!               \ |. / 
!!                \|./
!!       ----------+----------------> x
!!
!!       l_1 = u - cs   eigenvalue
!!       l_2 = u        eigenvalue (contact)
!!       l_3 = u + cs   eigenvalue
!!
!!       only density jumps across l_2
!!
!!  References:
!!
!!   CG:   Colella & Glaz 1985, JCP, 59, 264.
!!
!!   CW:   Colella & Woodward 1984, JCP, 54, 174.
!!
!!   Fry:  Fryxell et al. 2000, ApJS, 131, 273.
!!
!!   Toro: Toro 1999, ``Riemann Solvers and Numerical Methods for Fluid
!!         Dynamcs: A Practical Introduction, 2nd Ed.'', Springer-Verlag
!!
!! ARGUMENTS
!!
!! numIntCells :
!! numCells :
!! rhoav :
!! uav :
!! utav :
!! uttav :
!! pav :
!! urell :
!! ugrdl :
!! game :
!! gameav :
!! xnav :
!! x :
!!
!!
!!
!!***
module riemanCalc
use cudafor
#include "constants.h"
#include "Flash.h"
contains
subroutine rieman (numIntCells, numCells, &
                   rhoav, uav, utav, uttav, pav, &
                   urell, ugrdl, game, gameav, xnav, x)
                   

  use Hydro_data, ONLY: hy_numXn, &
                        hy_gmelft, hy_gmergt, &
                        hy_plft,   hy_prght,  &
                        hy_clft,   hy_crght,  &
                        hy_ulft,   hy_urght,  &
                        hy_vlft,   hy_vrght,  &
                        hy_utlft,  hy_utrght, &
                        hy_uttlft, hy_uttrgt, &
                        hy_xnlft,  hy_xnrght, &
                        hy_smallp, hy_smallu, &
                        hy_smlrho, hy_nriem,  &
                        hy_gmclft, hy_gmcrgt,hy_pstor, &
                        hy_riemanTol
  use Driver_interface, ONLY : Driver_abortFlash


  implicit none
!! Arguments ---------------------------------- 

  integer, intent (IN) :: numIntCells,numCells
  real, intent(IN), DIMENSION(numCells) :: x
  real, intent(IN), DIMENSION(numCells) :: ugrdl, game
  real, intent(OUT), DIMENSION(numCells) :: uav, rhoav, utav, uttav, pav, &
                               urell, gameav
  real, intent(OUT), DIMENSION(numCells,hy_numXn) :: xnav


!! Local variable ---------------------------------
    !--------------------------------------------------------------------------

    ! We carry around two adiabatic indices (gammas).  gamc is usually
    ! referred to as gamma_1, and is d(log P)/d(log rho) (CG Eq. 7).  game
    ! is CG Eq. 8.      

    ! calculate limits on gamma based on the values in the neighboring zones
    ! gamfac is the max gamma factor in CG Eq. 31, and is used over and over,
    ! so store it for efficiency.

 
  real, device, allocatable, DIMENSION(:)::uavDev
real, device, allocatable, DIMENSION(:)::rhoavDev
real, device, allocatable, DIMENSION(:)::utavDev
real, device, allocatable, DIMENSION(:)::uttavDev
real, device, allocatable, DIMENSION(:)::pavDev
real, device, allocatable, DIMENSION(:)::urellDev
real, device, allocatable, DIMENSION(:)::gameavDev
  real, device, allocatable, DIMENSION(:)::val1
  real, device, allocatable, DIMENSION(:)::val2
real, device, allocatable, DIMENSION(:)::ugrdlDev
real, device, allocatable, DIMENSION(:)::gameDev
real, device, allocatable, DIMENSION(:)::numXn
real, device, allocatable, DIMENSION(:)::gmelft
real, device, allocatable, DIMENSION(:)::gmergt
real, device, allocatable, DIMENSION(:)::plft
real, device, allocatable, DIMENSION(:)::prght
real, device, allocatable, DIMENSION(:)::clft
real, device, allocatable, DIMENSION(:)::crght
real, device, allocatable, DIMENSION(:)::ulft
real, device, allocatable, DIMENSION(:)::vlft
real, device, allocatable, DIMENSION(:)::vrght
real, device, allocatable, DIMENSION(:)::utlft
real, device, allocatable, DIMENSION(:)::uttlft
real, device, allocatable, DIMENSION(:)::utrght
real, device, allocatable, DIMENSION(:)::uttrgt
real, device, allocatable, DIMENSION(:,:)::xnlft
real, device, allocatable, DIMENSION(:,:)::xnrght
real, device, allocatable, DIMENSION(:)::smallp
real, device, allocatable, DIMENSION(:)::smallu
real, device, allocatable, DIMENSION(:)::smlrho
real, device, allocatable, DIMENSION(:)::nriem
real, device, allocatable, DIMENSION(:)::gmclft
real, device, allocatable, DIMENSION(:)::gmcrgt
real, device, allocatable, DIMENSION(:)::pstor
real, device, allocatable, DIMENSION(:)::riemanTol
real, device, allocatable, DIMENSION(:)::errorFlag
real, device, allocatable, DIMENSION(:,:)::xnavDev
integer::numIntCells5
real, DIMENSION(:)::eFlagDev,value
type(dim3)::dimGrid,dimBlock

numIntCells5=numIntCells+5
allocate(xnavDev(numCells,hy_numXn))
allocate(uavDev(numCells))
allocate(rhoavDev(numCells))
allocate(utavDev(numCells))
allocate(uttavDev(numCells))
allocate(pavDev(numCells))
allocate(urellDev(numCells))
allocate(gameavDev(numCells))
allocate(val1(numCells))
allocate(val2(numIntCells5))
allocate(ugrdlDev(numIntCells5))
allocate(gameDev(numIntCells5))
allocate(numXn(numIntCells5))
allocate(gmelft(numIntCells5))
allocate(gmergt(numIntCells5))
allocate(plft(numIntCells5))
allocate(prght(numIntCells5))
allocate(clft(numIntCells5))
allocate(crght(numIntCells5))
allocate(ulft(numIntCells5))
allocate(vlft(numIntCells5))
allocate(vrght(numIntCells5))
allocate(utlft(numIntCells5))
allocate(uttlft(numIntCells5))
allocate(utrght(numIntCells5))
allocate(uttrgt(numIntCells5))
allocate(xnlft(MAXCELLS,numIntCells5))
allocate(xnrght(MAXCELLS,numIntCells5))
allocate(smallp(numIntCells5))
allocate(smallu(numIntCells5))
allocate(smlrho(numIntCells5))
allocate(nriem(numIntCells5))
allocate(gmclft(numIntCells5))
allocate(gmcrgt(numIntCells5))
allocate(pstor(numIntCells5))
allocate(riemanTol(numIntCells5))
allocate(errorFlag(numCells))
val1=numCells
val2=numIntCells5
value=0
xnavDev=xnav(1:numCells,1:hy_numXn)
utavDev=utav(1:numCells)
uttavDev=uttav(1:numCells)
pavDev=pav(1:numCells)
urellDev=urell(1:numCells)
gameavDev=gameav(1:numCells)
rhoavDev=rhoav(1:numCells)
uavDev=uav(1:numCells)
ugrdlDev=ugrdl(1:numIntCells5)
gameDev=game(1:numIntCells5)
numXn=hy_numXn
gmelft=hy_gmelft(1:numIntCells5)
gmergt=hy_gmergt(1:numIntCells5)
plft=hy_plft(1:numIntCells5)
prght=hy_prght(1:numIntCells5)
clft=hy_clft(1:numIntCells5)
crght=hy_crght(1:numIntCells5)
ulft=hy_ulft(1:numIntCells5)
vlft=hy_vlft(1:numIntCells5)
vrght=hy_vrght(1:numIntCells5)
utlft=hy_utlft(1:numIntCells5)
utrght=hy_utrght(1:numIntCells5)
uttlft=hy_uttlft(1:numIntCells5)
uttrgt=hy_uttrgt(1:numIntCells5)
xnlft=hy_xnlft(1:MAXCELLS,1:numIntCells5)
xnrght=hy_xnrght(1:MAXCELLS,1:numIntCells5)
smallp=hy_smallp
smallu=hy_smallu
smlrho=hy_smlrho
nriem=hy_nriem
gmclft=hy_gmclft(1:numIntCells5)
gmcrgt=hy_gmcrgt(1:numIntCells5)
pstor=hy_pstor(1:numIntCells5)
riemanTol=hy_riemanTol

dimGrid=dim3(numIntCells5/16,numIntCells5/16,1)
dimBlock=dim3(16,16,1)

call rieman_kernel<<<dimGrid,dimBlock>>>(val1,val2,ugrdlDev,gameDev,numXn,gmelft,gmergt,plft,prght,clft,crght,ulft,vlft,vrght,utlft,uttlft,utrght,uttrgt,xnlft,xnrght,smallp,smallu,smlrho,nriem,gmclft,gmcrgt,pstor,riemanTol,&
utavDev,uttavDev,pavDev,urellDev,gameavDev,rhoavDev,uavDev,xnavDev)
  


return
end subroutine rieman

attributes (global) subroutine rieman_kernel(val1,val2,ugrdlDev,gameDev,numXn,gmelft,gmergt,plft,prght,clft,crght,ulft,vlft,vrght,utlft,uttlft,utrght,uttrgt,xnlft,xnrght,smallp,smallu,smlrho,nriem,gmclft,gmcrgt,pstor,riemanTol,&
utavDev,uttavDev,pavDev,urellDev,gameavDev,rhoavDev,uavDev,xnavDev)


 
real, DIMENSION(:)::val1,val2,ugrdlDev,gameDev,numXn,gmelft,gmergt,plft,prght,clft,crght,ulft,vlft,vrght,utlft,utrght,uttlft,uttrgt,smallp,smallu,smlrho,nriem,gmclft,gmcrgt,pstor,riemanTol,utavDev,uttavDev,pavDev,urellDev,gameavDev,rhoavDev,uavDev

real, DIMENSION(:,:):: xnlft,xnrght,xnavDev
real, DIMENSION(:) :: wlft, wrght, pstar, ustar, vstar, cestar, &
       rhostr, westar, ps, us, uts, utts, vs, rhos, ces, ws, wes, &
       gmstar, games, gamcs


  real, DIMENSION(:) :: pstar1, pstar2, gmstrl, gmstrr, &

       &   wlft1, wrght1, gmin, gmax, &
       &   gamfac, aux
  real, DIMENSION(:) :: scrch1, scrch2, scrch3, scrch4

  real  ::  ge, gc, ustrl1, ustrr1, ustrl2, ustrr2, &
       & delu1, delu2, pres_err,mxVal

  integer :: i, j, k, n,ierr,counter


  character(len=1), save :: dirs(3) = (/ 'x', 'y', 'z' /)

  real, parameter :: small_dp = 1.e2 * epsilon(1.e0)

do i = 5, val2(1)
     aux(i)    = sqrt (0.5e0 * (gameDev(i) - 1.0e0) / gameDev(i))
     ge        = 0.5e0 * (gmelft(i) + gmergt(i))
     gc        = 0.5e0 * (gmclft(i) + gmcrgt(i))
     gamfac(i) = (1.e0 - ge / gc) * (ge - 1.e0)
     gmin(i)   = min (gameDev(i-1), gameDev(i), gameDev(i+1))
     gmax(i)   = max (gameDev(i-1), gameDev(i), gameDev(i+1))
  enddo
  
    ! construct first guess for secant iteration by assuming that the nonlinear 
    ! wave speed is equal to the sound speed -- the resulting expression is the
    ! same as Toro, Eq. 9.28 in the Primitive Variable Riemann Solver (PVRS).
    ! See also Fry Eq. 72.
    
  do i = 5, val2(1)
     pstar1(i) = prght(i) - plft(i) -crght(i) * (urght(i) - ulft(i))
     pstar1(i) = plft(i) + pstar1(i) * (clft(i) / (clft(i) + crght(i)))
     pstar1(i) = max (smallp(1), pstar1(i))
  enddo

    ! calculate approximation jump in gamma acrosss the interface based on the 
    ! first guess for the pressure jump.  There is a left and right 'star' region,
    ! so we need gamma add both places.  Use CG Eq. 31 and 32, with definitions
    ! as in CG Eq. 33.
    
  do i = 5, val2(1)
     gmstrl(i) = gamfac(i) * (pstar1(i) - plft(i))
     gmstrl(i) = gmelft(i) + 2.e0 * gmstrl(i) / (pstar1(i) + plft(i))
     
     gmstrr(i) = gamfac(i) * (pstar1(i) - prght(i))
     gmstrr(i) = gmergt(i) + 2.e0 * gmstrr(i) / (pstar1(i) + prght(i))
     
     gmstrl(i) = max (gmin(i), min( gmstrl(i), gmax(i)))
     gmstrr(i) = max (gmin(i), min( gmstrr(i), gmax(i)))
  enddo

    ! calculate nonlinear wave speeds for the left and right moving waves based
    ! on the first guess for the pressure jump.  Again, there is a left and a 
    ! right wave speed.  Compute this using CG Eq. 34.
    
  do i = 5, val2(1)
     scrch1(i) = pstar1(i) - (gmstrl(i) - 1.e0) * plft(i) &
          & / (gmelft(i) - 1.e0)
     if (scrch1(i) .EQ. 0.e0) scrch1(i) = hy_smallp
     
     wlft1(i)  = pstar1(i) + 0.5e0 * (gmstrl(i) - 1.e0) &
          & * (pstar1(i) + plft(i))
     wlft1(i)  = (pstar1(i) - plft(i)) * wlft1(i) / (vlft(i) * scrch1(i))
     wlft1(i)  = sqrt(abs(wlft1(i)))
     

     scrch2(i) = pstar1(i) - (gmstrr(i) - 1.e0) * prght(i) /(gmergt(i) - 1.e0)
     
     if (scrch2(i) .EQ. 0.e0) scrch2(i) = smallp(1)
     
     wrght1(i) = pstar1(i) + 0.5e0 * (gmstrr(i) - 1.e0) &
          & * (pstar1(i) + prght(i))
     wrght1(i) = (pstar1(i) - prght(i)) * wrght1(i) / (vrght(i) * scrch2(i))
     wrght1(i) = sqrt(abs(wrght1(i)))
     
       ! if the pressure jump is small, the wave speed is just the sound speed

     if (abs (pstar1(i) - plft(i)) < small_dp*(pstar1(i) + plft(i))) wlft1(i) = hy_clft(i)
     wlft1(i)  = max (wlft1(i),  aux(i) * clft(i))
     
     if (abs (pstar1(i) - prght(i)) < small_dp*((pstar1(i) + prght(i)))) wrght1(i) = crght(i)
     wrght1(i) = max (wrght1(i), aux(i) * crght(i))
  enddo

    ! construct second guess for the pressure using the nonlinear wave speeds
    ! from the first guess.  This is basically the same thing we did to get
    ! pstar1, except now we are using the better wave speeds instead of the 
    ! sound speed.

  do i = 5, val2(1)
     pstar2(i) = prght(i) - plft(i) - wrght1(i) * (urght(i) - ulft(i))
     pstar2(i) = plft(i) + pstar2(i) * wlft1(i) / (wlft1(i) + wrght1(i))
     pstar2(i) = max (smallp(1), pstar2(i))
  enddo

    ! begin the secant iteration -- see CG Eq. 17 for details.  We will continue to
    ! interate for convergence until the error falls below tol (in which case, 
    ! things are good), or we hit hy_nriem iterations (in which case we have a 
    ! problem, and we spit out an error).

  do i = 5, val2(1)
     
     pstor(1) = pstar1(i)
     pstor(2) = pstar2(i)
     
     do n = 1, nriem(1)
        
        ! new values for the gamma at the "star" state -- again, using CG Eq. 31
          
        gmstrl(i) = gamfac(i) * (pstar2(i) - hy_plft(i))
        gmstrl(i) = gmelft(i) + 2.e0 * gmstrl(i) / (pstar2(i) + plft(i))
        
        gmstrr(i) = gamfac(i) * (pstar2(i) - prght(i))
        gmstrr(i) = gmergt(i) + 2.e0 * gmstrr(i) / (pstar2(i) + prght(i))
        
        gmstrl(i) = max (gmin(i), min (gmax(i), gmstrl(i)))
        gmstrr(i) = max (gmin(i), min (gmax(i), gmstrr(i)))
        
        ! new nonlinear wave speeds, using CG Eq. 34 and the updated gammas
          
        scrch1(i) = pstar2(i) - (gmstrl(i) - 1.e0) * plft(i) &
             & / (gmelft(i) - 1.e0)
        if (scrch1(i) .EQ. 0.e0) scrch1(i) = smallp(1)
        
        wlft(i)   = pstar2(i) + 0.5e0 * (gmstrl(i) - 1.e0) &
             & * (pstar2(i) + plft(i))
        wlft(i)   = (pstar2(i) - plft(i)) * wlft(i) / (vlft(i) * scrch1(i))
        wlft(i)   = sqrt(abs(wlft(i)))

        scrch2(i) = pstar2(i) - (gmstrr(i) - 1.e0) * prght(i) /(gmergt(i) - 1.e0)

        if (scrch2(i) .EQ. 0.e0) scrch2(i) = smallp(1)
        
        wrght(i)  = pstar2(i) + 0.5e0 * (gmstrr(i) - 1.e0) &
             & * (pstar2(i) + prght(i))
        wrght(i)  = (pstar2(i) - prght(i)) * wrght(i) / (vrght(i) * scrch2(i))
        wrght(i)  = sqrt(abs(wrght(i)))
        
        ! if the pressure jump is small, the wave speed is just the sound speed

        if (abs (pstar2(i) - hy_plft(i)) < small_dp*(pstar2(i) + plft(i))) wlft(i) = clft(i)
        wlft(i)  = max (wlft(i), aux(i) * clft(i))
        
        if (abs (pstar2(i) - prght(i)) < small_dp*(pstar2(i) + prght(i))) wrght(i) =crght(i)
        wrght(i) = max (wrght(i), aux(i) * crght(i))

        ! compute the velocities in the "star" state -- using CG Eq. 18 -- ustrl2 and
        ! ustrr2 are the velocities they define there.  ustrl1 and ustrl2 seem to be
        ! the velocities at the last time, since pstar1 is the old 'star' pressure, and
        ! wlft1 is the old wave speed.
        
        ustrl1    =  ulft(i) - (pstar1(i) -  plft(i)) /  wlft1(i)
        ustrr1    = urght(i) + (pstar1(i) - prght(i)) / wrght1(i)
        ustrl2    = ulft(i) - (pstar2(i) - plft(i)) /   wlft(i)
        ustrr2    = urght(i) + (pstar2(i) - prght(i)) /  wrght(i)
        
        delu1     = ustrl1 - ustrr1
        delu2     = ustrl2 - ustrr2
        scrch1(i) = delu2  - delu1
        
        if (abs(pstar2(i)-pstar1(i)) .le. smallp(1)) scrch1(i) = 0.e0
        
        if (abs(scrch1(i)) .lt. smallu(1)) then
           delu2 = 0.e0
           scrch1(i) = 1.e0
        endif

        ! pressure at the "star" state -- using CG Eq. 18

        pstar(i)  = pstar2(i) - delu2 * (pstar2(i) - pstar1(i)) / scrch1(i)
        pstar(i)  = max (smallp(1), pstar(i))
        
        ! check for convergence of iteration, hy_riemanTol is a run-time parameter
        
        pres_err = abs(pstar(i)-pstar2(i)) / pstar(i)
        if (pres_err .lt. riemanTol(1)) goto 10
        
        ! reset variables for next iteration
          
        pstar1(i) = pstar2(i)
        pstar2(i) = pstar(i)
        pstor(n+2) = pstar(i)
        
        wlft1(i)  = wlft(i)
        wrght1(i) = wrght(i)
        
     enddo
     
     n = n - 1
     
     ! print error message and stop code if iteration fails to converge
     
!     print *, ' '
 !    print *, 'Nonconvergence in subroutine rieman'
  !   print *, ' '
   !  print *, 'Zone index       = ', i
    ! print *, 'Zone center      = ', x(i)
     !print *, 'Iterations tried = ', n+2
    ! print *, 'Pressure error   = ', pres_err
    ! print *, 'rieman_tol       = ', hy_riemanTol
    ! print *, ' '
    ! print *, 'pL       = ', hy_plft(i),   ' pR       =', hy_prght(i)
    ! print *, 'uL       = ', hy_ulft(i),   ' uR       =', hy_urght(i)
    ! print *, 'cL       = ', hy_clft(i),   ' cR       =', hy_crght(i)
    ! print *, 'gamma_eL = ', hy_gmelft(i), ' gamma_eR =', hy_gmergt(i)
    ! print *, 'gamma_cL = ', hy_gmclft(i), ' gamma_cR =', hy_gmcrgt(i)
    ! print *, ' '
    ! print *, 'Iteration history:'
    ! print *, ' '
    ! print '(A4, 2X, A20)', 'n', 'p*'
    ! do j = 1, n+2
    !    print '(I4, 2X, E20.12)', j, hy_pstor(j)
    ! enddo
    ! print *, ' '
    ! print *, 'Terminating execution.'

       
       ! land here if the iterations have converged
       
return
10     continue
     
  enddo

! end of secant iteration

! calculate fluid velocity for the "star" state -- this comes from the shock
! jump equations, Fry Eq. 68 and 69.  The ustar velocity can be computed
! using either the jump eq. for a left moving or right moving shock -- we use
! the average of the two.

  do i = 5, val2(1)
     scrch3(i) = ulft (i) - (pstar(i) - plft(i)) /  wlft(i)
     scrch4(i) = urght(i) + (pstar(i) - prght(i)) / wrght(i)
     ustar(i)  = 0.5e0 * (scrch3(i) + scrch4(i))
  enddo

! account for grid velocity

  do i = 5, val2(1)
     urellDev(i)   = ustar(i) - ugrdl(i)
     scrch1(i)  = sign (1.e0, urellDev(i))
  enddo

! decide which state is located at the zone iterface based on the values 
! of the wave speeds.  This is just saying that if ustar > 0, then the state
! is U_L.  if ustar < 0, then the state on the axis is U_R.

  do i = 5, val2(1)
     
     scrch2(i) = 0.5e0 * ( 1.e0 + scrch1(i))
     scrch3(i) = 0.5e0 * ( 1.e0 - scrch1(i))
     
     ps(i)    = plft(i)   * scrch2(i) + prght(i)  * scrch3(i)
     us(i)    = ulft(i)   * scrch2(i) + urght(i)  * scrch3(i)
     uts(i)   =utlft(i)  * scrch2(i) + utrght(i) * scrch3(i)
     utts(i)  =uttlft(i) * scrch2(i) + uttrgt(i) * scrch3(i)
     vs(i)    = vlft(i)   * scrch2(i) + vrght(i)  * scrch3(i)
     games(i) = gmelft(i) * scrch2(i) + gmergt(i) * scrch3(i)
     gamcs(i) = gmclft(i) * scrch2(i) + gmcrgt(i) * scrch3(i)
     
     rhos(i)  = 1.e0 / vs(i)
     rhos(i)  = max (smlrho(1), rhos(i))
     
     vs(i)    = 1.e0 / rhos(i)
     ws(i)    = wlft(i) * scrch2(i) + wrght(i) * scrch3(i)
     ces(i)   = sqrt (gamcs(i) * ps(i) * vs(i))
     
     ! compute rhostar, using the shock jump condition (Fry Eq. 80)
     
     vstar(i)  = vs(i) - (pstar(i) - ps(i)) / ws(i) / ws(i)
     rhostr(i) = 1.e0 / vstar(i)
     cestar(i) = sqrt (gamcs(i) * pstar(i) * vstar(i))
     
! compute some factors, Fry Eq. 81 and 82       

     wes(i)    = ces(i)    - scrch1(i) * us(i)
     westar(i) = cestar(i) - scrch1(i) * ustar(i)
     
     scrch4(i) = ws(i) * vs(i) - scrch1(i) * us(i)
     
     
     if (pstar(i) - ps(i) .ge. 0.e0) then
        wes(i)    = scrch4(i)
        westar(i) = scrch4(i)
     endif
     
     wes(i)    = wes(i)    + scrch1(i) * ugrdl(i)
     westar(i) = westar(i) + scrch1(i) * ugrdl(i)
  enddo
  
  do i = 5, val2(1)
     gamfac(i) = (1.e0 - games(i) / gamcs(i)) * (games(i) - 1.e0)
     gmstar(i) = gamfac(i) * (pstar(i) - ps(i))
     gmstar(i) = games(i) + 2.e0 * gmstar(i) / (pstar(i) + ps(i))
     gmstar(i) = max (gmin(i), min (gmax(i), gmstar(i)))
  enddo
  
  do n = 1, numXn(1) 
     do i = 5, val2(1)
        xnavDev(i,n) =xnlft(i,n) * scrch2(i) + xnrght(i,n) * scrch3(i)
     enddo
  enddo
  
! compute correct state for rarefaction fan by linear interpolation

  do i = 5, val2(1)
     scrch1(i) = max (wes(i) - westar(i), wes(i) + westar(i), smallu(i))
     scrch1(i) =     (wes(i) + westar(i)) / scrch1(i)
     
     scrch1(i) = 0.5e0 * (1.e0 + scrch1(i))
     scrch2(i) =          1.e0 - scrch1(i)
     
     rhoavDev(i)  = scrch1(i) * rhostr(i) + scrch2(i) * rhos (i)
     uavDev  (i)  = scrch1(i) * ustar(i)  + scrch2(i) * us(i)
     utavDev (i)  = uts(i)
     uttavDev(i)  = utts(i)
     pavDev(i) = scrch1(i) * pstar(i)  + scrch2(i) * ps(i)
     gameavDev(i) = scrch1(i) * gmstar(i) + scrch2(i) * games(i)
  enddo
  
  do i = 5, val2(1)
     if (westar(i) .ge. 0.e0) then
        rhoavDev(i)  = rhostr(i)
        uavDev(i)    = ustar(i)
        pavDev(i)    = pstar(i)
        gameavDev(i) = gmstar(i)
     endif
     
     if (wes(i) .lt. 0.e0) then
        rhoavDev(i)  = rhos(i)
        uavDev(i)    = us(i)
        pavDev(i)    = ps(i)
        gameavDev(i) = games(i)
     endif
     
     urellDev(i) = uavDev(i) - ugrdl(i)
  enddo

 
end subroutine rieman_kernel
end module riemanCalc

The error occurs at the line “end subroutine_rieman_kernel”

Any help would be great!

Hi jmckennon,

Internal compiler error. unexpected runtime function call 0

This is a generic compiler error where the user or compiler has added a function call that is not supported on a device. If it’s a user error, then the compiler should be catching it and issuing a semantic error. If it’s compiler generated, we need to disable the optimization that’s adding the call.

In looking through the code, I don’t see anything obvious so I’ll need to compile the source to determine the issue. Do you mind posting the code for the “constants.h” and “Flash.h” include files as well as the source for the Hydro_data and Driver_interface modules. If it’s too large to post, please send the file to PGI Customer Service (trs@pgroup.com) and ask them to forward them to me.

Thanks,
Mat

I emailed the files over to customer service for you.

You should have the driver interface module now, thanks!!

Thanks jmckennon.

The problem is that you forgot to declare or misspelled some of your array variables. So when you accessed the undeclared “myarray(i)”, the compiler interprets this as a function call. Early version of the compiler unfortunately gave this unhelpful error message. As of the 10.8, you’d see the following error:

PGF90-S-0155-Calls from device code to a host function are allowed only in emulation mode - myarray (foo.F90: 311)

Using “implicit none” would have caught this error are well.

Hope this helps,
Mat

Hi Mat,

I included implicit none in the kernel routine and this helped catch those errors, which I fixed. I now am getting a horde of runtime function calls and the compiler isn’t telling me what they are (I have version 10.6).

PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unsupported procedure     869 (rieman.F90: 629)
PGF90-S-0000-Internal compiler error. unexpected runtime function call       0 (rieman.F90: 629)
PGF90-F-0008-Error limit exceeded (rieman.F90: 629)
PGF90/x86-64 Linux 10.6-0: compilation aborted
gmake: *** [rieman.o] Error 2
gmake: *** Waiting for unfinished jobs....

I emailed a copy of my changed rieman.F90 code to support.

Thanks for the help!
Justin

I’ve gotten rid of the runtime function error, but now I’m getting a different error. I tried placing everything in the module data section but started getting errors regarding the arrays for which I’m calculating the values for in my code. I tried passing the arrays after allocating them and filling them with zeros but still have no luck. The errors say:

PGF90-S-0042-wrght is a duplicate dummy argument (rieman.F90: 470)
PGF90-S-0043-Illegal attempt to redefine symbol wrght (rieman.F90: 473)
PGF90-W-0119-Redundant specification for wrght (rieman.F90: 473)
0 inform, 1 warnings, 2 severes, 0 fatal for rieman_kernel


!!****if* source/physics/Hydro/HydroMain/split/PPM/PPMKernel/rieman
!!
!! NAME
!! 
!!  rieman
!!
!! SYNOPSIS
!!
!!       call rieman ( integer(IN) :: numIntCells, 
!!                     integer(IN) :: numCells, 
!!                     real(OUT)   :: rhoav(numCells), 
!!                     real(OUT)   :: uav(numCells), 
!!                     real(OUT)   :: utav(numCells), 
!!                     real(OUT)   :: uttav(numCells), 
!!                     real(OUT)   :: pav(numCells), 
!!                     real(OUT)   :: urell(numCells), 
!!                     real(IN)    :: ugrdl(numCells), 
!!                     real(IN)    :: game(numCells), 
!!                     real(OUT)   :: gameav(numCells), 
!!                     real(OUT)   :: xnav(numCells, hy_numXn), 
!!                     real(IN) :: x(numCells))
!!                 
!!
!!
!! DESCRIPTION
!!  
!!  Solve riemann shock tube problem for a general equation of state using 
!!  the method of Colella and Glaz.  Use a two shock approximation, and
!!  linearly interpolation between the head and tail of a rarefaction to
!!  treat rarefactions.
!!
!!  Take as input the effective left and right states, obtained by 
!!  integrating the parabolic reconstructions of the data over the domain
!!  of dependence of each of the characteristics on the respective side
!!  of the interface.  This is accomplished by states().  Return the
!!  solution to Riemann's problem on axis -- this is used in computing
!!  the fluxes.
!!
!!  The Riemann problem for the Euler's equation produces 4 states, 
!!  separated by the three characteristics (u - cs, u, u + cs):
!!
!!
!!        l_1      t    l_2       l_3
!!         \       ^   .       /
!!          \  *L  |   . *R   /
!!           \     |  .     /
!!            \    |  .    /
!!        L    \   | .   /    R
!!              \  | .  /
!!               \ |. / 
!!                \|./
!!       ----------+----------------> x
!!
!!       l_1 = u - cs   eigenvalue
!!       l_2 = u        eigenvalue (contact)
!!       l_3 = u + cs   eigenvalue
!!
!!       only density jumps across l_2
!!
!!  References:
!!
!!   CG:   Colella & Glaz 1985, JCP, 59, 264.
!!
!!   CW:   Colella & Woodward 1984, JCP, 54, 174.
!!
!!   Fry:  Fryxell et al. 2000, ApJS, 131, 273.
!!
!!   Toro: Toro 1999, ``Riemann Solvers and Numerical Methods for Fluid
!!         Dynamcs: A Practical Introduction, 2nd Ed.'', Springer-Verlag
!!
!! ARGUMENTS
!!
!! numIntCells :
!! numCells :
!! rhoav :
!! uav :
!! utav :
!! uttav :
!! pav :
!! urell :
!! ugrdl :
!! game :
!! gameav :
!! xnav :
!! x :
!!
!!
!!
!!***
module riemanCalc
use cudafor
implicit none
#include "constants.h"
#include "Flash.h"
contains
subroutine rieman (numIntCells, numCells, &
                   rhoav, uav, utav, uttav, pav, &
                   urell, ugrdl, game, gameav, xnav, x)
                   

  use Hydro_data, ONLY: hy_numXn, &
                        hy_gmelft, hy_gmergt, &
                        hy_plft,   hy_prght,  &
                        hy_clft,   hy_crght,  &
                        hy_ulft,   hy_urght,  &
                        hy_vlft,   hy_vrght,  &
                        hy_utlft,  hy_utrght, &
                        hy_uttlft, hy_uttrgt, &
                        hy_xnlft,  hy_xnrght, &
                        hy_smallp, hy_smallu, &
                        hy_smlrho, hy_nriem,  &
                        hy_gmclft, hy_gmcrgt,hy_pstor, &
                        hy_riemanTol
  use Driver_interface, ONLY : Driver_abortFlash


  implicit none
!! Arguments ---------------------------------- 

  integer, intent (IN) :: numIntCells,numCells
  real, intent(IN), DIMENSION(numCells) :: x
  real, intent(IN), DIMENSION(numCells) :: ugrdl, game
  real, intent(OUT), DIMENSION(numCells) :: uav, rhoav, utav, uttav, pav, &
                               urell, gameav
  real, intent(OUT), DIMENSION(numCells,hy_numXn) :: xnav


  integer :: i, j, k, n,ierr,counter
  
  character(len=1), save :: dirs(3) = (/ 'x', 'y', 'z' /)

  real, parameter :: small_dp = 1.e2 * epsilon(1.e0)

real, device, allocatable, DIMENSION(:) :: wlft, wrght, pstar, ustar, vstar, cestar, &
       rhostr, westar, ps, us, uts, utts, vs, rhos, ces, ws, wes, &
       gmstar, games, gamcs



  real, device, allocatable, DIMENSION(:) :: pstar1, pstar2, gmstrl, gmstrr, &

       &   wlft1, wrght1, gmin, gmax, &
       &   gamfac, aux
  real, device, allocatable, DIMENSION(:) :: scrch1, scrch2, scrch3, scrch4

  real, device, allocatable ::  ge, gc, ustrl1, ustrr1, ustrl2, ustrr2, &
       & delu1, delu2, pressErr,mxVal


!! Local variable ---------------------------------
    !--------------------------------------------------------------------------

    ! We carry around two adiabatic indices (gammas).  gamc is usually
    ! referred to as gamma_1, and is d(log P)/d(log rho) (CG Eq. 7).  game
    ! is CG Eq. 8.      

    ! calculate limits on gamma based on the values in the neighboring zones
    ! gamfac is the max gamma factor in CG Eq. 31, and is used over and over,
    ! so store it for efficiency.
integer::numIntCells5


  real, device, allocatable, DIMENSION(:)::urght 
  real, device, allocatable, DIMENSION(:)::uavDev
real, device, allocatable, DIMENSION(:)::rhoavDev
real, device, allocatable, DIMENSION(:)::utavDev
real, device, allocatable, DIMENSION(:)::uttavDev
real, device, allocatable, DIMENSION(:)::pavDev
real, device, allocatable, DIMENSION(:)::urellDev
real, device, allocatable, DIMENSION(:)::gameavDev
  real, device, allocatable, DIMENSION(:)::val1
  real, device, allocatable, DIMENSION(:)::val2
real, device, allocatable, DIMENSION(:)::ugrdlDev
real, device, allocatable, DIMENSION(:)::gameDev
real, device, allocatable, DIMENSION(:)::numXn
real, device, allocatable, DIMENSION(:)::gmelft
real, device, allocatable, DIMENSION(:)::gmergt
real, device, allocatable, DIMENSION(:)::plft
real, device, allocatable, DIMENSION(:)::prght
real, device, allocatable, DIMENSION(:)::clft
real, device, allocatable, DIMENSION(:)::crght
real, device, allocatable, DIMENSION(:)::ulft
real, device, allocatable, DIMENSION(:)::vlft
real, device, allocatable, DIMENSION(:)::vrght
real, device, allocatable, DIMENSION(:)::utlft
real, device, allocatable, DIMENSION(:)::uttlft
real, device, allocatable, DIMENSION(:)::utrght
real, device, allocatable, DIMENSION(:)::uttrgt
real, device, allocatable, DIMENSION(:,:)::xnlft
real, device, allocatable, DIMENSION(:,:)::xnrght
real, device, allocatable, DIMENSION(:)::smallp
real, device, allocatable, DIMENSION(:)::smallu
real, device, allocatable, DIMENSION(:)::smlrho
real, device, allocatable, DIMENSION(:)::nriem
real, device, allocatable, DIMENSION(:)::gmclft
real, device, allocatable, DIMENSION(:)::gmcrgt
real, device, allocatable, DIMENSION(:)::pstor
real, device, allocatable, DIMENSION(:)::riemanTol
real, device, allocatable, DIMENSION(:)::errorFlag
real, device, allocatable, DIMENSION(:,:)::xnavDev
real, DIMENSION(numIntCells5)::DummyArray
type(dim3)::dimGrid,dimBlock

numIntCells5=numIntCells+5
val2=numIntCells5
do i=1,numIntCells5

DummyArray(i)=0
enddo

allocate(ge)
allocate(gc)
allocate(ustrl1)
allocate(ustrr1)
allocate(ustrl2)
allocate(ustrr2)
allocate(delu1)
allocate(delu2)
allocate(pressErr)
allocate(mxVal)
allocate(pstar1(numIntCells5))
allocate(pstar2(numIntCells5))
allocate(gmstrl(numIntCells5))
allocate(gmstrr(numIntCells5))
allocate(wlft1(numIntCells5))
allocate(wrght1(numIntCells5))
allocate(gmin(numIntCells5))
allocate(gmax(numIntCells5))
allocate(gamfac(numIntCells5))
allocate(aux(numIntCells5))
allocate(scrch1(numIntCells5))
allocate(scrch2(numIntCells5))
allocate(scrch3(numIntCells5))
allocate(scrch4(numIntCells5))
allocate(wlft(numIntCells5))
allocate(wrght(numIntCells5))
allocate(pstar(numIntCells5))
allocate(ustar(numIntCells5))
allocate(vstar(numIntCells5))
allocate(cestar(numIntCells5))
allocate(rhostr(numIntCells5))
allocate(westar(numIntCells5))
allocate(ps(numIntCells5))
allocate(us(numIntCells5))
allocate(uts(numIntCells5))
allocate(utts(numIntCells5))
allocate(vs(numIntCells5))
allocate(rhos(numIntCells5))
allocate(ces(numIntCells5))
allocate(ws(numIntCells5))
allocate(wes(numIntCells5))
allocate(gmstar(numIntCells5))
allocate(games(numIntCells5))
allocate(gamcs(numIntCells5))




allocate(xnavDev(numCells,hy_numXn))
allocate(uavDev(numCells))
allocate(rhoavDev(numCells))
allocate(utavDev(numCells))
allocate(uttavDev(numCells))
allocate(pavDev(numCells))
allocate(urellDev(numCells))
allocate(gameavDev(numCells))
allocate(val1(numCells))
allocate(val2(numIntCells5))
allocate(ugrdlDev(numIntCells5))
allocate(gameDev(numIntCells5))
allocate(numXn(numIntCells5))
allocate(gmelft(numIntCells5))
allocate(gmergt(numIntCells5))
allocate(plft(numIntCells5))
allocate(prght(numIntCells5))
allocate(clft(numIntCells5))
allocate(crght(numIntCells5))
allocate(ulft(numIntCells5))
allocate(vlft(numIntCells5))
allocate(vrght(numIntCells5))
allocate(utlft(numIntCells5))
allocate(uttlft(numIntCells5))
allocate(utrght(numIntCells5))
allocate(uttrgt(numIntCells5))
allocate(xnlft(MAXCELLS,numIntCells5))
allocate(xnrght(MAXCELLS,numIntCells5))
allocate(smallp(numIntCells5))
allocate(smallu(numIntCells5))
allocate(smlrho(numIntCells5))
allocate(nriem(numIntCells5))
allocate(gmclft(numIntCells5))
allocate(gmcrgt(numIntCells5))
allocate(pstor(numIntCells5))
allocate(riemanTol(numIntCells5))
!allocate(errorFlag(numCells))
allocate(urght(numIntCells5))


pstar1=DummyArray(1:numIntCells5)
pstar2=DummyArray(1:numIntCells5)
gmstrl=DummyArray(1:numIntCells5)
gmstrr=DummyArray(1:numIntCells5)
wlft1=DummyArray(1:numIntCells5)
wrght1=DummyArray(1:numIntCells5)
gmin=DummyArray(1:numIntCells5)
gmax=DummyArray(1:numIntCells5)
gamfac=DummyArray(1:numIntCells5)
aux=DummyArray(1:numIntCells5)
scrch1=DummyArray(1:numIntCells5)
scrch2=DummyArray(1:numIntCells5)
scrch3=DummyArray(1:numIntCells5)
scrch4=DummyArray(1:numIntCells5)
wlft=DummyArray(1:numIntCells5)
wrght=DummyArray(1:numIntCells5)
pstar=DummyArray(1:numIntCells5)
ustar=DummyArray(1:numIntCells5)
vstar=DummyArray(1:numIntCells5)
cestar=DummyArray(1:numIntCells5)
rhostr=DummyArray(1:numIntCells5)
westar=DummyArray(1:numIntCells5)
ps=DummyArray(1:numIntCells5)
us=DummyArray(1:numIntCells5)
uts=DummyArray(1:numIntCells5)
utts=DummyArray(1:numIntCells5)
vs=DummyArray(1:numIntCells5)
rhos=DummyArray(1:numIntCells5)
ces=DummyArray(1:numIntCells5)
ws=DummyArray(1:numIntCells5)
wes=DummyArray(1:numIntCells5)
gmstar=DummyArray(1:numIntCells5)
games=DummyArray(1:numIntCells5)
gamcs=DummyArray(1:numIntCells5)
xnavDev=xnav(1:numCells,1:hy_numXn)
utavDev=utav(1:numCells)
uttavDev=uttav(1:numCells)
pavDev=pav(1:numCells)
urellDev=urell(1:numCells)
gameavDev=gameav(1:numCells)
rhoavDev=rhoav(1:numCells)
uavDev=uav(1:numCells)
ugrdlDev=ugrdl(1:numIntCells5)
gameDev=game(1:numIntCells5)
numXn=hy_numXn
gmelft=hy_gmelft(1:numIntCells5)
gmergt=hy_gmergt(1:numIntCells5)
plft=hy_plft(1:numIntCells5)
prght=hy_prght(1:numIntCells5)
clft=hy_clft(1:numIntCells5)
crght=hy_crght(1:numIntCells5)
ulft=hy_ulft(1:numIntCells5)
vlft=hy_vlft(1:numIntCells5)
vrght=hy_vrght(1:numIntCells5)
utlft=hy_utlft(1:numIntCells5)
utrght=hy_utrght(1:numIntCells5)
uttlft=hy_uttlft(1:numIntCells5)
uttrgt=hy_uttrgt(1:numIntCells5)
xnlft=hy_xnlft(1:MAXCELLS,1:numIntCells5)
xnrght=hy_xnrght(1:MAXCELLS,1:numIntCells5)
smallp=hy_smallp
smallu=hy_smallu
smlrho=hy_smlrho
nriem=hy_nriem
gmclft=hy_gmclft(1:numIntCells5)
gmcrgt=hy_gmcrgt(1:numIntCells5)
pstor=hy_pstor(1:numIntCells5)
riemanTol=hy_riemanTol
urght=hy_urght(1:numIntCells5)
!dimGrid=dim3(numIntCells5/16,numIntCells5/16,1)
!dimBlock=dim3(16,16,1)

call rieman_kernel<<<numIntCells5/16,16>>>(wlft,wrght,pstar,ustar,vstar,cestar,rhostr,westar,ps,us,uts,utts,vs,rhos,ces,ws,wes,gmstar,games,gamcs,aux,gamfac,gmin,gmax,pstar1,gmstrl,gmstrr,scrch1,wlft1,scrch2,wrght)
uav=uavDev(1:numIntCells5)
rhoav=rhoavDev(1:numIntCells5)
utav=utavDev(1:numIntCells5)
uttav=uttavDev(1:numIntCells5)
pav=pavDev(1:numIntCells5)
urell=urellDev(1:numIntCells5)
gameav=gameavDev(1:numIntCells5)
xnav=xnavDev(1:numCells,1:hy_numXn)

deallocate(ge)
deallocate(gc)
deallocate(ustrl1)
deallocate(ustrr1)
deallocate(ustrl2)
deallocate(ustrr2)
deallocate(delu1)
deallocate(delu2)
deallocate(pressErr)
deallocate(mxVal)
deallocate(pstar1)
deallocate(pstar2)
deallocate(gmstrl)
deallocate(gmstrr)
deallocate(wlft1)
deallocate(wrght1)
deallocate(gmin)
deallocate(gmax)
deallocate(gamfac)
deallocate(aux)
deallocate(scrch1)
deallocate(scrch2)
deallocate(scrch3)
deallocate(scrch4)
deallocate(wlft)
deallocate(wrght)
deallocate(pstar)
deallocate(ustar)
deallocate(vstar)
deallocate(cestar)
deallocate(rhostr)
deallocate(westar)
deallocate(ps)
deallocate(us)
deallocate(uts)
deallocate(utts)
deallocate(vs)
deallocate(rhos)
deallocate(ces)
deallocate(ws)
deallocate(wes)
deallocate(gmstar)
deallocate(games)
deallocate(gamcs)
deallocate(xnavDev)
deallocate(uavDev)
deallocate(rhoavDev)
deallocate(utavDev)
deallocate(uttavDev)
deallocate(pavDev)
deallocate(urellDev)
deallocate(gameavDev)
deallocate(val1)
deallocate(val2)
deallocate(ugrdlDev)
deallocate(gameDev)
deallocate(numXn)
deallocate(gmelft)
deallocate(gmergt)
deallocate(plft)
deallocate(prght)
deallocate(clft)
deallocate(crght)
deallocate(ulft)
deallocate(vlft)
deallocate(vrght)
deallocate(utlft)
deallocate(uttlft)
deallocate(utrght)
deallocate(uttrgt)
deallocate(xnlft)
deallocate(xnrght)
deallocate(smallp)
deallocate(smallu)
deallocate(smlrho)
deallocate(nriem)
deallocate(gmclft)
deallocate(gmcrgt)
deallocate(pstor)
deallocate(riemanTol)
!allocate(errorFlag)
deallocate(urght)

  


return
end subroutine rieman

attributes (global) subroutine rieman_kernel(wlft,wrght,pstar,ustar,vstar,cestar,rhostr,westar,ps,us,uts,utts,vs,rhos,ces,ws,wes,gmstar,games,gamcs,aux,gamfac,gmin,gmax,pstar1,gmstrl,gmstrr,scrch1,wlft1,scrch2,wrght)


real,DIMENSION(:)::wlft,wrght,pstar,ustar,vstar,cestar,rhostr,westar,ps,us,uts,utts,vs,rhos,ces,ws,wes,gmstar,games,gamcs,aux,gamfac,gmin,gmax,pstar1,gmstrl,gmstrr,scrch1,wlft1,scrch2,wrght



 


do i = 5, val2(1)
     aux(i)    = sqrt (0.5e0 * (gameDev(i) - 1.0e0) / gameDev(i))
     ge        = 0.5e0 * (gmelft(i) + gmergt(i))
     gc        = 0.5e0 * (gmclft(i) + gmcrgt(i))
     gamfac(i) = (1.e0 - ge / gc) * (ge - 1.e0)
     gmin(i)   = min (gameDev(i-1), gameDev(i), gameDev(i+1))
     gmax(i)   = max (gameDev(i-1), gameDev(i), gameDev(i+1))
  enddo
  
    ! construct first guess for secant iteration by assuming that the nonlinear 
    ! wave speed is equal to the sound speed -- the resulting expression is the
    ! same as Toro, Eq. 9.28 in the Primitive Variable Riemann Solver (PVRS).
    ! See also Fry Eq. 72.
    
  do i = 5, val2(1)
     pstar1(i) = prght(i) - plft(i) -crght(i) * (urght(i) - ulft(i))
     pstar1(i) = plft(i) + pstar1(i) * (clft(i) / (clft(i) + crght(i)))
     pstar1(i) = max (smallp(1), pstar1(i))
  enddo

    ! calculate approximation jump in gamma acrosss the interface based on the 
    ! first guess for the pressure jump.  There is a left and right 'star' region,
    ! so we need gamma add both places.  Use CG Eq. 31 and 32, with definitions
    ! as in CG Eq. 33.
    
  do i = 5, val2(1)
     gmstrl(i) = gamfac(i) * (pstar1(i) - plft(i))
     gmstrl(i) = gmelft(i) + 2.e0 * gmstrl(i) / (pstar1(i) + plft(i))
     
     gmstrr(i) = gamfac(i) * (pstar1(i) - prght(i))
     gmstrr(i) = gmergt(i) + 2.e0 * gmstrr(i) / (pstar1(i) + prght(i))
     
     gmstrl(i) = max (gmin(i), min( gmstrl(i), gmax(i)))
     gmstrr(i) = max (gmin(i), min( gmstrr(i), gmax(i)))
  enddo

    ! calculate nonlinear wave speeds for the left and right moving waves based
    ! on the first guess for the pressure jump.  Again, there is a left and a 
    ! right wave speed.  Compute this using CG Eq. 34.
    
  do i = 5, val2(1)
     scrch1(i) = pstar1(i) - (gmstrl(i) - 1.e0) * plft(i) &
          & / (gmelft(i) - 1.e0)
     if (scrch1(i) .EQ. 0.e0) scrch1(i) = smallp(1)
     
     wlft1(i)  = pstar1(i) + 0.5e0 * (gmstrl(i) - 1.e0) &
          & * (pstar1(i) + plft(i))
     wlft1(i)  = (pstar1(i) - plft(i)) * wlft1(i) / (vlft(i) * scrch1(i))
     wlft1(i)  = sqrt(abs(wlft1(i)))
     

     scrch2(i) = pstar1(i) - (gmstrr(i) - 1.e0) * prght(i) /(gmergt(i) - 1.e0)
     
     if (scrch2(i) .EQ. 0.e0) scrch2(i) = smallp(1)
     
     wrght1(i) = pstar1(i) + 0.5e0 * (gmstrr(i) - 1.e0) &
          & * (pstar1(i) + prght(i))
     wrght1(i) = (pstar1(i) - prght(i)) * wrght1(i) / (vrght(i) * scrch2(i))
     wrght1(i) = sqrt(abs(wrght1(i)))
     
       ! if the pressure jump is small, the wave speed is just the sound speed

     if (abs (pstar1(i) - plft(i)) < small_dp*(pstar1(i) + plft(i))) wlft1(i) = clft(i)
     wlft1(i)  = max (wlft1(i),  aux(i) * clft(i))
     
     if (abs (pstar1(i) - prght(i)) < small_dp*((pstar1(i) + prght(i)))) wrght1(i) = crght(i)
     wrght1(i) = max (wrght1(i), aux(i) * crght(i))
  enddo

    ! construct second guess for the pressure using the nonlinear wave speeds
    ! from the first guess.  This is basically the same thing we did to get
    ! pstar1, except now we are using the better wave speeds instead of the 
    ! sound speed.

  do i = 5, val2(1)
     pstar2(i) = prght(i) - plft(i) - wrght1(i) * (urght(i) - ulft(i))
     pstar2(i) = plft(i) + pstar2(i) * wlft1(i) / (wlft1(i) + wrght1(i))
     pstar2(i) = max (smallp(1), pstar2(i))
  enddo

    ! begin the secant iteration -- see CG Eq. 17 for details.  We will continue to
    ! interate for convergence until the error falls below tol (in which case, 
    ! things are good), or we hit hy_nriem iterations (in which case we have a 
    ! problem, and we spit out an error).

  do i = 5, val2(1)
     
     pstor(1) = pstar1(i)
     pstor(2) = pstar2(i)
     
     do n = 1, nriem(1)
        
        ! new values for the gamma at the "star" state -- again, using CG Eq. 31
          
        gmstrl(i) = gamfac(i) * (pstar2(i) - plft(i))
        gmstrl(i) = gmelft(i) + 2.e0 * gmstrl(i) / (pstar2(i) + plft(i))
        
        gmstrr(i) = gamfac(i) * (pstar2(i) - prght(i))
        gmstrr(i) = gmergt(i) + 2.e0 * gmstrr(i) / (pstar2(i) + prght(i))
        
        gmstrl(i) = max (gmin(i), min (gmax(i), gmstrl(i)))
        gmstrr(i) = max (gmin(i), min (gmax(i), gmstrr(i)))
        
        ! new nonlinear wave speeds, using CG Eq. 34 and the updated gammas
          
        scrch1(i) = pstar2(i) - (gmstrl(i) - 1.e0) * plft(i) &
             & / (gmelft(i) - 1.e0)
        if (scrch1(i) .EQ. 0.e0) scrch1(i) = smallp(1)
        
        wlft(i)   = pstar2(i) + 0.5e0 * (gmstrl(i) - 1.e0) &
             & * (pstar2(i) + plft(i))
        wlft(i)   = (pstar2(i) - plft(i)) * wlft(i) / (vlft(i) * scrch1(i))
        wlft(i)   = sqrt(abs(wlft(i)))

        scrch2(i) = pstar2(i) - (gmstrr(i) - 1.e0) * prght(i) /(gmergt(i) - 1.e0)

        if (scrch2(i) .EQ. 0.e0) scrch2(i) = smallp(1)
        
        wrght(i)  = pstar2(i) + 0.5e0 * (gmstrr(i) - 1.e0) &
             & * (pstar2(i) + prght(i))
        wrght(i)  = (pstar2(i) - prght(i)) * wrght(i) / (vrght(i) * scrch2(i))
        wrght(i)  = sqrt(abs(wrght(i)))
        
        ! if the pressure jump is small, the wave speed is just the sound speed

        if (abs (pstar2(i) - plft(i)) < small_dp*(pstar2(i) + plft(i))) wlft(i) = clft(i)
        wlft(i)  = max (wlft(i), aux(i) * clft(i))
        
        if (abs (pstar2(i) - prght(i)) < small_dp*(pstar2(i) + prght(i))) wrght(i) =crght(i)
        wrght(i) = max (wrght(i), aux(i) * crght(i))

        ! compute the velocities in the "star" state -- using CG Eq. 18 -- ustrl2 and
        ! ustrr2 are the velocities they define there.  ustrl1 and ustrl2 seem to be
        ! the velocities at the last time, since pstar1 is the old 'star' pressure, and
        ! wlft1 is the old wave speed.
        
        ustrl1    =  ulft(i) - (pstar1(i) -  plft(i)) /  wlft1(i)
        ustrr1    = urght(i) + (pstar1(i) - prght(i)) / wrght1(i)
        ustrl2    = ulft(i) - (pstar2(i) - plft(i)) /   wlft(i)
        ustrr2    = urght(i) + (pstar2(i) - prght(i)) /  wrght(i)
        
        delu1     = ustrl1 - ustrr1
        delu2     = ustrl2 - ustrr2
        scrch1(i) = delu2  - delu1
        
        if (abs(pstar2(i)-pstar1(i)) .le. smallp(1)) scrch1(i) = 0.e0
        
        if (abs(scrch1(i)) .lt. smallu(1)) then
           delu2 = 0.e0
           scrch1(i) = 1.e0
        endif

        ! pressure at the "star" state -- using CG Eq. 18

        pstar(i)  = pstar2(i) - delu2 * (pstar2(i) - pstar1(i)) / scrch1(i)
        pstar(i)  = max (smallp(1), pstar(i))
        
        ! check for convergence of iteration, hy_riemanTol is a run-time parameter
        
        pressErr = abs(pstar(i)-pstar2(i)) / pstar(i)
        if (pres_err .lt. riemanTol(1)) goto 10
        
        ! reset variables for next iteration
          
        pstar1(i) = pstar2(i)
        pstar2(i) = pstar(i)
        pstor(n+2) = pstar(i)
        
        wlft1(i)  = wlft(i)
        wrght1(i) = wrght(i)
        
     enddo
     
     n = n - 1
     
     ! print error message and stop code if iteration fails to converge
     
!     print *, ' '
 !    print *, 'Nonconvergence in subroutine rieman'
  !   print *, ' '
   !  print *, 'Zone index       = ', i
    ! print *, 'Zone center      = ', x(i)
     !print *, 'Iterations tried = ', n+2
    ! print *, 'Pressure error   = ', pres_err
    ! print *, 'rieman_tol       = ', hy_riemanTol
    ! print *, ' '
    ! print *, 'pL       = ', hy_plft(i),   ' pR       =', hy_prght(i)
    ! print *, 'uL       = ', hy_ulft(i),   ' uR       =', hy_urght(i)
    ! print *, 'cL       = ', hy_clft(i),   ' cR       =', hy_crght(i)
    ! print *, 'gamma_eL = ', hy_gmelft(i), ' gamma_eR =', hy_gmergt(i)
    ! print *, 'gamma_cL = ', hy_gmclft(i), ' gamma_cR =', hy_gmcrgt(i)
    ! print *, ' '
    ! print *, 'Iteration history:'
    ! print *, ' '
    ! print '(A4, 2X, A20)', 'n', 'p*'
    ! do j = 1, n+2
    !    print '(I4, 2X, E20.12)', j, hy_pstor(j)
    ! enddo
    ! print *, ' '
    ! print *, 'Terminating execution.'

       
       ! land here if the iterations have converged
       
return
10     continue
     
  enddo

! end of secant iteration

! calculate fluid velocity for the "star" state -- this comes from the shock
! jump equations, Fry Eq. 68 and 69.  The ustar velocity can be computed
! using either the jump eq. for a left moving or right moving shock -- we use
! the average of the two.

  do i = 5, val2(1)
     scrch3(i) = ulft (i) - (pstar(i) - plft(i)) /  wlft(i)
     scrch4(i) = urght(i) + (pstar(i) - prght(i)) / wrght(i)
     ustar(i)  = 0.5e0 * (scrch3(i) + scrch4(i))
  enddo

! account for grid velocity

  do i = 5, val2(1)
     urellDev(i)   = ustar(i) - ugrdlDev(i)
     scrch1(i)  = sign (1.e0, urellDev(i))
  enddo

! decide which state is located at the zone iterface based on the values 
! of the wave speeds.  This is just saying that if ustar > 0, then the state
! is U_L.  if ustar < 0, then the state on the axis is U_R.

  do i = 5, val2(1)
     
     scrch2(i) = 0.5e0 * ( 1.e0 + scrch1(i))
     scrch3(i) = 0.5e0 * ( 1.e0 - scrch1(i))
     
     ps(i)    = plft(i)   * scrch2(i) + prght(i)  * scrch3(i)
     us(i)    = ulft(i)   * scrch2(i) + urght(i)  * scrch3(i)
     uts(i)   =utlft(i)  * scrch2(i) + utrght(i) * scrch3(i)
     utts(i)  =uttlft(i) * scrch2(i) + uttrgt(i) * scrch3(i)
     vs(i)    = vlft(i)   * scrch2(i) + vrght(i)  * scrch3(i)
     games(i) = gmelft(i) * scrch2(i) + gmergt(i) * scrch3(i)
     gamcs(i) = gmclft(i) * scrch2(i) + gmcrgt(i) * scrch3(i)
     
     rhos(i)  = 1.e0 / vs(i)
     rhos(i)  = max (smlrho(1), rhos(i))
     
     vs(i)    = 1.e0 / rhos(i)
     ws(i)    = wlft(i) * scrch2(i) + wrght(i) * scrch3(i)
     ces(i)   = sqrt (gamcs(i) * ps(i) * vs(i))
     
     ! compute rhostar, using the shock jump condition (Fry Eq. 80)
     
     vstar(i)  = vs(i) - (pstar(i) - ps(i)) / ws(i) / ws(i)
     rhostr(i) = 1.e0 / vstar(i)
     cestar(i) = sqrt (gamcs(i) * pstar(i) * vstar(i))
     
! compute some factors, Fry Eq. 81 and 82       

     wes(i)    = ces(i)    - scrch1(i) * us(i)
     westar(i) = cestar(i) - scrch1(i) * ustar(i)
     
     scrch4(i) = ws(i) * vs(i) - scrch1(i) * us(i)
     
     
     if (pstar(i) - ps(i) .ge. 0.e0) then
        wes(i)    = scrch4(i)
        westar(i) = scrch4(i)
     endif
     
     wes(i)    = wes(i)    + scrch1(i) * ugrdlDev(i)
     westar(i) = westar(i) + scrch1(i) * ugrdlDev(i)
  enddo
  
  do i = 5, val2(1)
     gamfac(i) = (1.e0 - games(i) / gamcs(i)) * (games(i) - 1.e0)
     gmstar(i) = gamfac(i) * (pstar(i) - ps(i))
     gmstar(i) = games(i) + 2.e0 * gmstar(i) / (pstar(i) + ps(i))
     gmstar(i) = max (gmin(i), min (gmax(i), gmstar(i)))
  enddo
  
  do n = 1, numXn(1) 
     do i = 5, val2(1)
        xnavDev(i,n) =xnlft(i,n) * scrch2(i) + xnrght(i,n) * scrch3(i)
     enddo
  enddo
  
! compute correct state for rarefaction fan by linear interpolation

  do i = 5, val2(1)
     scrch1(i) = max (wes(i) - westar(i), wes(i) + westar(i), smallu(i))
     scrch1(i) =     (wes(i) + westar(i)) / scrch1(i)
     
     scrch1(i) = 0.5e0 * (1.e0 + scrch1(i))
     scrch2(i) =          1.e0 - scrch1(i)
     
     rhoavDev(i)  = scrch1(i) * rhostr(i) + scrch2(i) * rhos (i)
     uavDev  (i)  = scrch1(i) * ustar(i)  + scrch2(i) * us(i)
     utavDev (i)  = uts(i)
     uttavDev(i)  = utts(i)
     pavDev(i) = scrch1(i) * pstar(i)  + scrch2(i) * ps(i)
     gameavDev(i) = scrch1(i) * gmstar(i) + scrch2(i) * games(i)
  enddo
  
  do i = 5, val2(1)
     if (westar(i) .ge. 0.e0) then
        rhoavDev(i)  = rhostr(i)
        uavDev(i)    = ustar(i)
        pavDev(i)    = pstar(i)
        gameavDev(i) = gmstar(i)
     endif
     
     if (wes(i) .lt. 0.e0) then
        rhoavDev(i)  = rhos(i)
        uavDev(i)    = us(i)
        pavDev(i)    = ps(i)
        gameavDev(i) = games(i)
     endif
     
     urellDev(i) = uavDev(i) - ugrdlDev(i)
  enddo

 return
 

end subroutine rieman_kernel
end module riemanCalc