Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

True mixed precision #55

Open
2 of 3 tasks
FlorianDeconinck opened this issue Jul 23, 2024 · 2 comments
Open
2 of 3 tasks

True mixed precision #55

FlorianDeconinck opened this issue Jul 23, 2024 · 2 comments
Assignees

Comments

@FlorianDeconinck
Copy link
Collaborator

FlorianDeconinck commented Jul 23, 2024

The Aer Activation port shows the usage of 64-bit literals in an otherwise 32-bit code

Until now we were operating under the assumption of a fully 32-bit or fully 64-bit precision calculation, with the exception of the occasional upcasting of a Field to keep precision up.

With this finding, we are back to the drawing board.

Fortran uses a "variable precision is the precision of the operation" technique to define ops precision between literals and variables. We could try to replicate this in GT4Py/DaCe to force "best precision" on single ops.

Another option is to work at NDSL level and have an override on a particular stencil to be at 64-bit, if GT4Py/DaCe allows for it.

Parent: GEOS-ESM/SMT-Nebulae#36


  • Create a simplified small reproducer, base of a future documentation, to show the 64/32 issue based on the Aer Activation code
  • Design a solution
  • Implement OR subtasks
@FlorianDeconinck
Copy link
Collaborator Author

Use case in UW

subroutine conden(p,thl,qt,th,qv,ql,qi,rvls,id_check)

      implicit none

      real, intent(in)     :: p
      real, intent(in)     :: thl
      real, intent(in)     :: qt
      real, intent(out)    :: th
      real, intent(out)    :: qv
      real, intent(out)    :: ql
      real, intent(out)    :: qi
      real, intent(out)    :: rvls
      integer, intent(out) :: id_check

      ! Local
      real*8               :: tc
      real                 :: temps,ps
      real*8               :: leff,nu,qc
      integer              :: iteration
      real*8               :: qs    ! Saturation specific humidity

      tc = thl*exnerfn(p)

!     nu = max(min((258._r8-tc)/20._r8,1.0_r8),0.0_r8)    ! ice fraction of condensate
      nu = ICE_FRACTION(real(tc),0.0,0.0)
      leff = (1._r8- nu)*xlv + nu*xls    ! effective latent heat

      temps = tc
      ps = p
      qs = GEOS_QSAT(temps, ps/100.)
      rvls = qs
 
      if ( qs .ge. qt ) then  ! no condensation
         id_check = 0
         qv = qt
         qc = 0.
         ql = 0.
         qi = 0.
         th = thl !tc/exnerfn(p)
      else                    ! condensation
         do iteration = 1,10
            temps = temps + ( (tc-temps)*cp/leff + qt - rvls )/( cp/leff + ep2*leff*rvls/(r*temps*temps) )
            qs = GEOS_QSAT(temps, ps/100.)
            rvls = qs
         end do
         qc = max( qt-qs, 0._r8 )
         qv = qt - qc
         ql = qc*(1._r8 - nu)
         qi = nu*qc
         th = temps/exnerfn(p)
         if ( abs((temps-(leff/cp)*qc)-tc) .ge. 1._r8 ) then
            id_check = 1
         else
            id_check = 0
         end if
      end if

      return
   end subroutine conden

@FlorianDeconinck
Copy link
Collaborator Author

@FlorianDeconinck FlorianDeconinck self-assigned this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant