Skip to content

Commit

Permalink
OpenACC port of atm_compute_vert_imp_coefs
Browse files Browse the repository at this point in the history
Initial OpenACC port of atm_compute_vert_imp_coefs.

- Separating the computation of cofrz into a separate parallel
  clause is required for correctness.
- Variables b_tri and c_tri are declared private in lieu of
  extending the storage to two dimensions, like a_tri.
  • Loading branch information
abishekg7 committed Nov 6, 2024
1 parent 61d9228 commit da32982
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/core_atmosphere/dynamics/mpas_atm_time_integration.F
Original file line number Diff line number Diff line change
Expand Up @@ -1894,32 +1894,46 @@ subroutine atm_compute_vert_imp_coefs_work(nCells, moist_start, moist_end, dts,
real (kind=RKIND) :: dtseps, c2, qtotal, rcv
real (kind=RKIND), dimension( nVertLevels ) :: b_tri, c_tri

MPAS_ACC_TIMER_START('atm_compute_vert_imp_coefs_work [ACC_data_xfer]')
!$acc enter data copyin(rdzw, zz, fzm, fzp, rdzu, cqw, p, t, qtot, rb, &
!$acc rtb, rt, pb)
!$acc enter data create(cofrz, cofwr, cofwz, coftz, cofwt, a_tri, b_tri, &
!$acc c_tri, alpha_tri, gamma_tri)
MPAS_ACC_TIMER_STOP('atm_compute_vert_imp_coefs_work [ACC_data_xfer]')

! set coefficients
dtseps = .5*dts*(1.+epssm)
rcv = rgas/(cp-rgas)
c2 = cp*rcv

!$acc parallel
!$acc loop
! MGD bad to have all threads setting this variable?
do k=1,nVertLevels
cofrz(k) = dtseps*rdzw(k)
end do

!$acc end parallel

!$acc parallel
!$acc loop gang worker private(b_tri,c_tri)
do iCell = cellSolveStart,cellSolveEnd ! we only need to do cells we are solving for, not halo cells

!DIR$ IVDEP
!$acc loop
do k=2,nVertLevels
cofwr(k,iCell) =.5*dtseps*gravity*(fzm(k)*zz(k,iCell)+fzp(k)*zz(k-1,iCell))
end do
coftz(1,iCell) = 0.0
!DIR$ IVDEP
!$acc loop
do k=2,nVertLevels
cofwz(k,iCell) = dtseps*c2*(fzm(k)*zz(k,iCell)+fzp(k)*zz(k-1,iCell)) &
*rdzu(k)*cqw(k,iCell)*(fzm(k)*p (k,iCell)+fzp(k)*p (k-1,iCell))
coftz(k,iCell) = dtseps* (fzm(k)*t (k,iCell)+fzp(k)*t (k-1,iCell))
end do
coftz(nVertLevels+1,iCell) = 0.0
!DIR$ IVDEP
!$acc loop
do k=1,nVertLevels

! qtotal = 0.
Expand All @@ -1940,6 +1954,7 @@ subroutine atm_compute_vert_imp_coefs_work(nCells, moist_start, moist_end, dts,
alpha_tri(1,iCell) = 0. ! note, this value is never used

!DIR$ IVDEP
!$acc loop vector
do k=2,nVertLevels
a_tri(k,iCell) = -cofwz(k ,iCell)* coftz(k-1,iCell)*rdzw(k-1)*zz(k-1,iCell) &
+cofwr(k ,iCell)* cofrz(k-1 ) &
Expand All @@ -1955,12 +1970,18 @@ subroutine atm_compute_vert_imp_coefs_work(nCells, moist_start, moist_end, dts,
+cofwt(k ,iCell)* coftz(k+1,iCell)*rdzw(k )
end do
!MGD VECTOR DEPENDENCE
!$acc loop seq
do k=2,nVertLevels
alpha_tri(k,iCell) = 1./(b_tri(k)-a_tri(k,iCell)*gamma_tri(k-1,iCell))
gamma_tri(k,iCell) = c_tri(k)*alpha_tri(k,iCell)
end do

end do ! loop over cells
!$acc end parallel

!$acc exit data copyout(cofrz, cofwr, cofwz, coftz, cofwt, a_tri, b_tri, &
!$acc c_tri, alpha_tri, gamma_tri)
!$acc exit data delete(rdzw, zz, fzm, fzp, rdzu, cqw, p, t, qtot, rb, rtb, rt, pb)

end subroutine atm_compute_vert_imp_coefs_work

Expand Down

0 comments on commit da32982

Please sign in to comment.