Skip to content

Commit e4c2509

Browse files
committed
Moving some OpenACC data movements to subroutines
1 parent 2d8e10f commit e4c2509

File tree

4 files changed

+194
-47
lines changed

4 files changed

+194
-47
lines changed

src/core_atmosphere/dynamics/mpas_atm_iau.F

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
! Additional copyright and license information can be found in the LICENSE file
66
! distributed with this code, or at http://mpas-dev.github.com/license.html
77
!
8+
9+
#ifdef MPAS_OPENACC
10+
#define MPAS_ACC_TIMER_START(X) call mpas_timer_start(X)
11+
#define MPAS_ACC_TIMER_STOP(X) call mpas_timer_stop(X)
12+
#else
13+
#define MPAS_ACC_TIMER_START(X)
14+
#define MPAS_ACC_TIMER_STOP(X)
15+
#endif
16+
817
module mpas_atm_iau
918

1019
use mpas_derived_types
@@ -15,17 +24,7 @@ module mpas_atm_iau
1524
use mpas_log, only : mpas_log_write
1625
use mpas_timer
1726

18-
!public :: atm_compute_iau_coef, atm_add_tend_anal_incr
19-
20-
21-
#ifdef MPAS_OPENACC
22-
#define MPAS_ACC_TIMER_START(X) call mpas_timer_start(X)
23-
#define MPAS_ACC_TIMER_STOP(X) call mpas_timer_stop(X)
24-
#else
25-
#define MPAS_ACC_TIMER_START(X)
26-
#define MPAS_ACC_TIMER_STOP(X)
27-
#endif
28-
27+
!public :: atm_compute_iau_coef, atm_add_tend_anal_incr
2928

3029
contains
3130

@@ -87,6 +86,39 @@ real (kind=RKIND) function atm_iau_coef(configs, itimestep, dt) result(wgt_iau)
8786
end if
8887

8988
end function atm_iau_coef
89+
90+
!==================================================================================================
91+
subroutine update_d2h_pre_add_tend_anal_incr(configs,structs)
92+
!==================================================================================================
93+
94+
implicit none
95+
96+
type (mpas_pool_type), intent(in) :: configs
97+
type (mpas_pool_type), intent(inout) :: structs
98+
99+
type (mpas_pool_type), pointer :: tend
100+
type (mpas_pool_type), pointer :: state
101+
type (mpas_pool_type), pointer :: diag
102+
103+
real (kind=RKIND), dimension(:,:), pointer :: rho_edge, rho_zz, theta_m
104+
real(kind=RKIND),dimension(:,:,:), pointer :: scalars, tend_scalars
105+
106+
call mpas_pool_get_subpool(structs, 'tend', tend)
107+
call mpas_pool_get_subpool(structs, 'state', state)
108+
call mpas_pool_get_subpool(structs, 'diag', diag)
109+
110+
MPAS_ACC_TIMER_START('atm_srk3: physics ACC_data_xfer')
111+
call mpas_pool_get_array(state, 'theta_m', theta_m, 1)
112+
call mpas_pool_get_array(state, 'scalars', scalars, 1)
113+
call mpas_pool_get_array(state, 'rho_zz', rho_zz, 2)
114+
call mpas_pool_get_array(diag , 'rho_edge', rho_edge)
115+
!$acc update self(theta_m, scalars, rho_zz, rho_edge)
116+
117+
call mpas_pool_get_array(tend, 'scalars_tend', tend_scalars)
118+
!$acc update self(tend_scalars)
119+
MPAS_ACC_TIMER_STOP('atm_srk3: physics ACC_data_xfer')
120+
121+
end subroutine update_d2h_pre_add_tend_anal_incr
90122

91123
!==================================================================================================
92124
subroutine atm_add_tend_anal_incr (configs, structs, itimestep, dt, tend_ru, tend_rtheta, tend_rho)
@@ -148,7 +180,6 @@ subroutine atm_add_tend_anal_incr (configs, structs, itimestep, dt, tend_ru, ten
148180
call mpas_pool_get_array(state, 'scalars', scalars, 1)
149181
call mpas_pool_get_array(state, 'rho_zz', rho_zz, 2)
150182
call mpas_pool_get_array(diag , 'rho_edge', rho_edge)
151-
!$acc update self(theta_m, scalars, rho_zz, rho_edge)
152183

153184
call mpas_pool_get_dimension(state, 'moist_start', moist_start)
154185
call mpas_pool_get_dimension(state, 'moist_end', moist_end)
@@ -161,8 +192,6 @@ subroutine atm_add_tend_anal_incr (configs, structs, itimestep, dt, tend_ru, ten
161192
! call mpas_pool_get_array(tend, 'rho_zz', tend_rho)
162193
! call mpas_pool_get_array(tend, 'theta_m', tend_theta)
163194
call mpas_pool_get_array(tend, 'scalars_tend', tend_scalars)
164-
!$acc update self(tend_scalars)
165-
MPAS_ACC_TIMER_STOP('atm_srk3: physics ACC_data_xfer')
166195

167196
call mpas_pool_get_array(tend_iau, 'theta', theta_amb)
168197
call mpas_pool_get_array(tend_iau, 'rho', rho_amb)

src/core_atmosphere/dynamics/mpas_atm_time_integration.F

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module atm_time_integration
2929

3030
#ifdef DO_PHYSICS
3131
use mpas_atmphys_driver_microphysics
32+
use mpas_atmphys_interface, only: update_d2h_pre_microphysics, update_h2d_post_microphysics
3233
use mpas_atmphys_todynamics
3334
use mpas_atmphys_utilities
3435
#endif
@@ -1985,6 +1986,7 @@ subroutine atm_srk3(domain, dt, itimestep, exchange_halo_group)
19851986
call mpas_timer_stop('atm_compute_moist_coefficients')
19861987

19871988
#ifdef DO_PHYSICS
1989+
call update_d2h_pre_physics_get_tend(block % configs, state, diag, tend)
19881990
call mpas_timer_start('physics_get_tend')
19891991
rk_step = 1
19901992
dynamics_substep = 1
@@ -1993,6 +1995,7 @@ subroutine atm_srk3(domain, dt, itimestep, exchange_halo_group)
19931995
tend_ru_physics, tend_rtheta_physics, tend_rho_physics, &
19941996
exchange_halo_group )
19951997
call mpas_timer_stop('physics_get_tend')
1998+
call update_h2d_post_physics_get_tend(block % configs, state, diag, tend)
19961999
#else
19972000
#ifndef MPAS_CAM_DYCORE
19982001
!
@@ -2008,6 +2011,7 @@ subroutine atm_srk3(domain, dt, itimestep, exchange_halo_group)
20082011
! IAU - Incremental Analysis Update
20092012
!
20102013
if (trim(config_IAU_option) /= 'off') then
2014+
call update_d2h_pre_add_tend_anal_incr(block % configs, block % structs)
20112015
call atm_add_tend_anal_incr(block % configs, block % structs, itimestep, dt, &
20122016
tend_ru_physics, tend_rtheta_physics, tend_rho_physics)
20132017
end if
@@ -2614,7 +2618,6 @@ subroutine atm_srk3(domain, dt, itimestep, exchange_halo_group)
26142618
!$acc update self(rthdynten)
26152619
MPAS_ACC_TIMER_STOP('atm_srk3: physics ACC_data_xfer')
26162620

2617-
26182621
!NOTE: The calculation of the tendency due to horizontal and vertical advection for the water vapor mixing ratio
26192622
!requires that the subroutine atm_advance_scalars_mono was called on the third Runge Kutta step, so that a halo
26202623
!update for the scalars at time_levs(1) is applied. A halo update for the scalars at time_levs(2) is done above.
@@ -2643,6 +2646,7 @@ subroutine atm_srk3(domain, dt, itimestep, exchange_halo_group)
26432646
MPAS_ACC_TIMER_STOP('atm_srk3: physics ACC_data_xfer')
26442647
!call microphysics schemes:
26452648
if (trim(config_microp_scheme) /= 'off') then
2649+
call update_d2h_pre_microphysics( block % configs, state, diag, 2)
26462650
call mpas_timer_start('microphysics')
26472651
!$OMP PARALLEL DO
26482652
do thread=1,nThreads
@@ -2651,6 +2655,7 @@ subroutine atm_srk3(domain, dt, itimestep, exchange_halo_group)
26512655
end do
26522656
!$OMP END PARALLEL DO
26532657
call mpas_timer_stop('microphysics')
2658+
call update_h2d_post_microphysics( block % configs, state, diag, tend, 2)
26542659
end if
26552660

26562661
!

src/core_atmosphere/physics/mpas_atmphys_interface.F

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
! distributed with this code, or at http://mpas-dev.github.com/license.html
77
!
88
!=================================================================================================================
9-
module mpas_atmphys_interface
10-
use mpas_kind_types
11-
use mpas_pool_routines
12-
13-
use mpas_atmphys_constants
14-
use mpas_atmphys_vars
15-
use mpas_timer
169

1710
#ifdef MPAS_OPENACC
1811
#define MPAS_ACC_TIMER_START(X) call mpas_timer_start(X)
@@ -22,6 +15,13 @@ module mpas_atmphys_interface
2215
#define MPAS_ACC_TIMER_STOP(X)
2316
#endif
2417

18+
module mpas_atmphys_interface
19+
use mpas_kind_types
20+
use mpas_pool_routines
21+
22+
use mpas_atmphys_constants
23+
use mpas_atmphys_vars
24+
use mpas_timer
2525

2626
implicit none
2727
private
@@ -555,6 +555,40 @@ subroutine MPAS_to_physics(configs,mesh,state,time_lev,diag,diag_physics,its,ite
555555

556556
end subroutine MPAS_to_physics
557557

558+
!=================================================================================================================
559+
subroutine update_d2h_pre_microphysics(configs,state,diag,time_lev)
560+
!=================================================================================================================
561+
562+
!input variables:
563+
type(mpas_pool_type),intent(in):: configs
564+
type(mpas_pool_type),intent(in):: state
565+
type(mpas_pool_type),intent(in):: diag
566+
567+
integer:: time_lev
568+
569+
!local pointers:
570+
real(kind=RKIND),dimension(:,:),pointer :: exner,pressure_b,w
571+
real(kind=RKIND),dimension(:,:),pointer :: rho_zz,theta_m,pressure_p
572+
real(kind=RKIND),dimension(:,:,:),pointer:: scalars
573+
574+
575+
MPAS_ACC_TIMER_START('update_d2h_pre_microphysics [ACC_data_xfer]')
576+
call mpas_pool_get_array(diag,'exner' ,exner )
577+
call mpas_pool_get_array(diag,'pressure_base',pressure_b)
578+
call mpas_pool_get_array(diag,'pressure_p' ,pressure_p)
579+
580+
call mpas_pool_get_array(state,'rho_zz' ,rho_zz ,time_lev)
581+
call mpas_pool_get_array(state,'theta_m',theta_m,time_lev)
582+
call mpas_pool_get_array(state,'w' ,w ,time_lev)
583+
!$acc update host(exner, pressure_b, pressure_p, rho_zz, theta_m, w)
584+
585+
call mpas_pool_get_array(state,'scalars',scalars,time_lev)
586+
!$acc update host(scalars)
587+
588+
MPAS_ACC_TIMER_STOP('update_d2h_pre_microphysics [ACC_data_xfer]')
589+
590+
end subroutine update_d2h_pre_microphysics
591+
558592
!=================================================================================================================
559593
subroutine microphysics_from_MPAS(configs,mesh,state,time_lev,diag,diag_physics,tend_physics,its,ite)
560594
!=================================================================================================================
@@ -598,22 +632,18 @@ subroutine microphysics_from_MPAS(configs,mesh,state,time_lev,diag,diag_physics,
598632
call mpas_pool_get_array(mesh,'zgrid',zgrid)
599633
call mpas_pool_get_array(mesh,'zz' ,zz )
600634

601-
MPAS_ACC_TIMER_START('atm_srk3: physics ACC_data_xfer')
602635
call mpas_pool_get_array(diag,'exner' ,exner )
603636
call mpas_pool_get_array(diag,'pressure_base',pressure_b)
604637
call mpas_pool_get_array(diag,'pressure_p' ,pressure_p)
605638

606639
call mpas_pool_get_array(state,'rho_zz' ,rho_zz ,time_lev)
607640
call mpas_pool_get_array(state,'theta_m',theta_m,time_lev)
608641
call mpas_pool_get_array(state,'w' ,w ,time_lev)
609-
!$acc update host(exner, pressure_b, pressure_p, rho_zz, theta_m, w)
610642

611643
call mpas_pool_get_dimension(state,'index_qv',index_qv)
612644
call mpas_pool_get_dimension(state,'index_qc',index_qc)
613645
call mpas_pool_get_dimension(state,'index_qr',index_qr)
614-
call mpas_pool_get_array(state,'scalars',scalars,time_lev)
615-
!$acc update host(scalars)
616-
MPAS_ACC_TIMER_STOP('atm_srk3: physics ACC_data_xfer')
646+
call mpas_pool_get_array(state,'scalars',scalars,time_lev)
617647
qv => scalars(index_qv,:,:)
618648
qc => scalars(index_qc,:,:)
619649
qr => scalars(index_qr,:,:)
@@ -1054,13 +1084,49 @@ subroutine microphysics_to_MPAS(configs,mesh,state,time_lev,diag,diag_physics,te
10541084
case default
10551085
end select mp_tend_select
10561086

1057-
MPAS_ACC_TIMER_START('atm_srk3: physics ACC_data_xfer')
1087+
end subroutine microphysics_to_MPAS
1088+
1089+
!=================================================================================================================
1090+
subroutine update_h2d_post_microphysics(configs,state,diag,tend,time_lev)
1091+
!=================================================================================================================
1092+
1093+
!input variables:
1094+
type(mpas_pool_type),intent(in):: configs
1095+
type(mpas_pool_type),intent(in):: state
1096+
type(mpas_pool_type),intent(in):: diag
1097+
type(mpas_pool_type),intent(inout):: tend
1098+
1099+
1100+
integer:: time_lev
1101+
1102+
!local pointers:
1103+
real(kind=RKIND),dimension(:,:),pointer :: exner,exner_b,pressure_b,rtheta_p,rtheta_b
1104+
real(kind=RKIND),dimension(:,:),pointer :: rho_zz,theta_m,pressure_p
1105+
real(kind=RKIND),dimension(:,:,:),pointer:: scalars
1106+
real(kind=RKIND),dimension(:,:),pointer :: rt_diabatic_tend
1107+
1108+
call mpas_pool_get_array(diag,'exner' ,exner )
1109+
call mpas_pool_get_array(diag,'exner_base' ,exner_b )
1110+
call mpas_pool_get_array(diag,'pressure_base',pressure_b)
1111+
call mpas_pool_get_array(diag,'pressure_p' ,pressure_p)
1112+
call mpas_pool_get_array(diag,'rtheta_base' ,rtheta_b )
1113+
call mpas_pool_get_array(diag,'rtheta_p' ,rtheta_p )
1114+
1115+
call mpas_pool_get_array(state,'rho_zz' ,rho_zz ,time_lev)
1116+
call mpas_pool_get_array(state,'theta_m',theta_m,time_lev)
1117+
1118+
call mpas_pool_get_array(state,'scalars',scalars,time_lev)
1119+
1120+
call mpas_pool_get_array(tend,'rt_diabatic_tend',rt_diabatic_tend)
1121+
1122+
1123+
MPAS_ACC_TIMER_START('update_h2d_post_microphysics [ACC_data_xfer]')
10581124
!$acc update device(exner, exner_b, pressure_b, pressure_p, rtheta_b)
10591125
!$acc update device(rtheta_p, rho_zz, theta_m, scalars)
10601126
!$acc update device(rt_diabatic_tend)
1061-
MPAS_ACC_TIMER_STOP('atm_srk3: physics ACC_data_xfer')
1127+
MPAS_ACC_TIMER_STOP('update_h2d_post_microphysics [ACC_data_xfer]')
10621128

1063-
end subroutine microphysics_to_MPAS
1129+
end subroutine update_h2d_post_microphysics
10641130

10651131
!=================================================================================================================
10661132
end module mpas_atmphys_interface

0 commit comments

Comments
 (0)