Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions src/core_atmosphere/dynamics/mpas_atm_time_integration.F
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#ifdef MPAS_OPENACC
#define MPAS_ACC_TIMER_START(X) call mpas_timer_start(X)
#define MPAS_ACC_TIMER_STOP(X) call mpas_timer_stop(X)
#define NEDGESONCELL_INNER_LOOP() do i=1,nEdgesOnCell(iCell)
#define NEDGESONCELL_OUTER_LOOP()
#else
#define MPAS_ACC_TIMER_START(X)
#define MPAS_ACC_TIMER_STOP(X)
#define NEDGESONCELL_OUTER_LOOP() do i=1,nEdgesOnCell(iCell)
#define NEDGESONCELL_INNER_LOOP()
#endif

module atm_time_integration
Expand Down Expand Up @@ -3972,7 +3976,7 @@ subroutine atm_advance_acoustic_step_work(nCells, nEdges, nCellsSolve, cellStart
end if

!$OMP BARRIER

call mpas_timer_start('atm_advance_acoustic_step_3976')
!$acc parallel default(present)
!$acc loop gang worker private(ts,rs)
do iCell=cellSolveStart,cellSolveEnd ! loop over all owned cells to solve
Expand All @@ -3997,14 +4001,22 @@ subroutine atm_advance_acoustic_step_work(nCells, nEdges, nCellsSolve, cellStart
rs(k) = 0.0
end do

!$acc loop seq
do i=1,nEdgesOnCell(iCell)
iEdge = edgesOnCell(i,iCell)
cell1 = cellsOnEdge(1,iEdge)
cell2 = cellsOnEdge(2,iEdge)
! When building this code for CPUs, the below macro will expand to "do i=1,nEdgesOnCell(iCell)",
! preserving the nested loop order as originally written, and optimized for CPU execution.
! However, when building for GPUs (presently with OpenACC), the order of the nested loops are
! effectively interchanged to yield better GPU performance, without affecting correctness. In
! the latter case, NEDGESONCELL_OUTER_LOOP expands to an empty string and NEDGESONCELL_INNER_LOOP
! now expands to "do i=1,nEdgesOnCell(iCell)".
NEDGESONCELL_OUTER_LOOP()
!DIR$ IVDEP
!$acc loop vector
do k=1,nVertLevels
!$acc loop seq
NEDGESONCELL_INNER_LOOP()

iEdge = edgesOnCell(i,iCell)
cell1 = cellsOnEdge(1,iEdge)
cell2 = cellsOnEdge(2,iEdge)
flux = edgesOnCell_sign(i,iCell)*dts*dvEdge(iEdge)*ru_p(k,iEdge) * invAreaCell(iCell)
rs(k) = rs(k)-flux
ts(k) = ts(k)-flux*0.5*(theta_m(k,cell2)+theta_m(k,cell1))
Expand Down Expand Up @@ -4046,8 +4058,25 @@ subroutine atm_advance_acoustic_step_work(nCells, nEdges, nCellsSolve, cellStart
+ cofwt(k-1,iCell)*(etp(k-1)*ts(k-1)+etm(k-1)*rtheta_pp(k-1,iCell)))
end do

! tridiagonal solve sweeping up and then down the column
!$acc loop vector
do k=1,nVertLevels
rho_pp(k,iCell) = rs(k)
rtheta_pp(k,iCell) = ts(k)
end do

#ifdef MPAS_OPENACC
end if
enddo
!$acc end parallel


!$acc parallel default(present)
!$acc loop gang worker
do iCell=cellSolveStart,cellSolveEnd ! loop over all owned cells to solve

if(specZoneMaskCell(iCell) == 0.0) then ! not specified zone, compute...
#endif
! tridiagonal solve sweeping up and then down the column
!MGD VECTOR DEPENDENCE
!$acc loop seq
do k=2,nVertLevels
Expand All @@ -4070,12 +4099,8 @@ subroutine atm_advance_acoustic_step_work(nCells, nEdges, nCellsSolve, cellStart
*(fzm(k)*rho_zz(k,iCell)+fzp(k)*rho_zz(k-1,iCell)) &
*w(k,iCell) )/(1.0+dts*dss(k,iCell)) &
- (rw_save(k ,iCell) - rw(k ,iCell))
end do


! accumulate (rho*omega)' for use later in scalar transport
!DIR$ IVDEP
!$acc loop vector
do k=2,nVertLevels
wwAvg(k,iCell) = wwAvg(k,iCell) + ewp(k)*rw_p(k,iCell)
end do

Expand All @@ -4084,9 +4109,9 @@ subroutine atm_advance_acoustic_step_work(nCells, nEdges, nCellsSolve, cellStart
!DIR$ IVDEP
!$acc loop vector
do k=1,nVertLevels
rho_pp(k,iCell) = rs(k) - dts*cofrz(k) *( ewp(k+1)*rw_p(k+1,iCell) &
rho_pp(k,iCell) = rho_pp(k,iCell) - dts*cofrz(k) *( ewp(k+1)*rw_p(k+1,iCell) &
-ewp(k )*rw_p(k ,iCell))
rtheta_pp(k,iCell) = ts(k) - dts*rdzw(k)*( ewp(k+1)*coftz(k+1,iCell)*rw_p(k+1,iCell) &
rtheta_pp(k,iCell) = rtheta_pp(k,iCell) - dts*rdzw(k)*( ewp(k+1)*coftz(k+1,iCell)*rw_p(k+1,iCell) &
-ewp(k )*coftz(k ,iCell)*rw_p(k ,iCell))
end do

Expand All @@ -4104,7 +4129,7 @@ subroutine atm_advance_acoustic_step_work(nCells, nEdges, nCellsSolve, cellStart

end do ! end of loop over cells
!$acc end parallel

call mpas_timer_stop('atm_advance_acoustic_step_3976')

end subroutine atm_advance_acoustic_step_work

Expand Down