Ignore:
Timestamp:
Sep 29, 2020 12:02:05 PM (4 years ago)
Author:
pavelkrc
Message:

Correct and improve OpenMP parallelization, fix numerical instabilities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/radiation_model_mod.f90

    r4708 r4713  
    2828! -----------------
    2929! $Id$
     30! Correct OpenMP parallelization including cycles with cumulative variables (J. Resler)
     31!
     32! 4708 2020-09-28 17:42:58Z suehring
    3033! - Bugfix, correct mapping of RRTMG heating rates, as well as incoming/outgoing
    3134!   radiation onto the topography-following grid
     
    59675970     REAL(wp)                          ::  pabs_pc_lwdifl     !< total absorbed LW radiation in plant canopy from sky in local processor (W)
    59685971     REAL(wp)                          ::  pabs_pc_lwdif      !< total absorbed LW radiation in plant canopy from sky in all processors (W)
    5969 
     5972!-   rotation related variables
    59705973     REAL(wp)                          ::  sun_direct_factor  !< factor for direct normal radiation from direct horizontal
    59715974     REAL(wp)                          ::  sin_rot            !< sine of rotation_angle
     
    60726075!--  Set up thermal radiation from surfaces
    60736076     mm = 1
     6077!--  following code depends on the order of the execution
     6078!--  do not parallelize by OpenMP
    60746079     DO  i = nxl, nxr
    60756080        DO  j = nys, nyn
     
    61596164
    61606165     IF ( surface_reflections)  THEN
     6166        !$OMP DO PRIVATE (i, j, k, isvf, isurf, isurfsrc) SCHEDULE (STATIC)
    61616167        DO  isvf = 1, nsvfl
    61626168           isurf = svfsurf(1, isvf)
     
    61736179           ENDIF
    61746180        ENDDO
     6181        !$OMP END DO
    61756182     ENDIF
    61766183!
    61776184!--  diffuse radiation using sky view factor
     6185     !$OMP DO PRIVATE (i, j, d, isurf) REDUCTION(+:pinswl, pinlwl) SCHEDULE (STATIC)
    61786186     DO isurf = 1, nsurfl
    61796187        j = surfl(iy, isurf)
     
    61936201        ENDIF
    61946202     ENDDO
     6203     !$OMP END DO
    61956204!
    61966205!--  MRT diffuse irradiance
     6206     !$OMP DO PRIVATE (i, j, imrt) SCHEDULE (STATIC)
    61976207     DO  imrt = 1, nmrtbl
    61986208        j = mrtbl(iy, imrt)
     
    62016211        mrtinlw(imrt) = mrtsky(imrt) * rad_lw_in_diff(j,i)
    62026212     ENDDO
     6213     !$OMP END DO
    62036214!
    62046215!--  Direct radiation
     
    62186229        isd = dsidir_rev(j, i)
    62196230!-- TODO: check if isd = -1 to report that this solar position is not precalculated
     6231        !$OMP DO PRIVATE (i, j, d, isurf)  REDUCTION(+:pinswl) SCHEDULE (STATIC)
    62206232        DO isurf = 1, nsurfl
    62216233           j = surfl(iy, isurf)
     
    62276239           pinswl = pinswl + surfinswdir(isurf) * facearea(d)
    62286240        ENDDO
     6241        !$OMP END DO
    62296242!
    62306243!--     MRT direct irradiance
     6244        !$OMP DO PRIVATE (i, j, imrt) SCHEDULE (STATIC)
    62316245        DO  imrt = 1, nmrtbl
    62326246           j = mrtbl(iy, imrt)
     
    62356249                                     * sun_direct_factor / 4.0_wp ! normal to sphere
    62366250        ENDDO
     6251        !$OMP END DO
    62376252     ENDIF
    62386253!
    62396254!--  MRT first pass thermal
     6255     !$OMP DO PRIVATE (imrtf, imrt, isurfsrc) SCHEDULE (STATIC)
    62406256     DO  imrtf = 1, nmrtf
    62416257        imrt = mrtfsurf(1, imrtf)
     
    62436259        mrtinlw(imrt) = mrtinlw(imrt) + mrtf(imrtf) * surfoutl(isurfsrc)
    62446260     ENDDO
     6261     !$OMP END DO
    62456262!
    62466263!--  Absorption in each local plant canopy grid box from the first atmospheric
     
    62526269         pcbinlw(:) = 0.0_wp
    62536270
     6271         !$OMP DO PRIVATE (icsf, ipcgb, i, j, k, kk, isurfsrc, pc_abs_frac, pcrad, asrc)          &
     6272         !$OMP&   REDUCTION(+:pinswl, pinlwl, pabslwl, pemitlwl, pabs_pc_lwdifl) SCHEDULE (STATIC)
    62546273         DO icsf = 1, ncsfl
    62556274             ipcgb = csfsurf(1, icsf)
     
    63096328             ENDIF
    63106329         ENDDO
     6330         !$OMP END DO
    63116331
    63126332         pcbinsw(:) = pcbinswdir(:) + pcbinswdif(:)
     
    63626382     ENDIF
    63636383
    6364 !-- Next passes of radiation interactions:
     6384!--  Next passes of radiation interactions:
    63656385!--  radiation reflections
    63666386
     
    64046424!
    64056425!--      Reflected radiation
     6426         !$OMP DO PRIVATE (isvf, isurf, isurfsrc) SCHEDULE (STATIC)
    64066427         DO isvf = 1, nsvfl
    64076428             isurf = svfsurf(1, isvf)
     
    64146435             ENDIF
    64156436         ENDDO
     6437         !$OMP END DO
    64166438!
    64176439!--      NOTE: PC absorbtion and MRT from reflected can both be done at once
     
    64216443!
    64226444!--      Radiation absorbed by plant canopy
     6445         !$OMP DO PRIVATE (icsf, ipcgb, isurfsrc, asrc) SCHEDULE (STATIC)
    64236446         DO  icsf = 1, ncsfl
    64246447             ipcgb = csfsurf(1, icsf)
     
    64356458             ENDIF
    64366459         ENDDO
     6460         !$OMP END DO
    64376461!
    64386462!--      MRT reflected
     6463         !$OMP DO PRIVATE (imrtf, imrt, isurfsrc) SCHEDULE (STATIC)
    64396464         DO  imrtf = 1, nmrtf
    64406465            imrt = mrtfsurf(1, imrtf)
     
    64436468            mrtinlw(imrt) = mrtinlw(imrt) + mrtf(imrtf) * surfoutl(isurfsrc)
    64446469         ENDDO
     6470         !$OMP END DO
    64456471
    64466472         IF ( trace_fluxes_above >= 0.0_wp )  THEN
     
    64646490     IF ( npcbl > 0 )  THEN
    64656491         pcm_heating_rate(:,:,:) = 0.0_wp
     6492         !$OMP DO PRIVATE (ipcgb, i, j, k, kk) REDUCTION(+:pabsswl) SCHEDULE (STATIC)
    64666493         DO ipcgb = 1, npcbl
    64676494             j = pcbl(iy, ipcgb)
     
    64766503             pabsswl = pabsswl + pcbinsw(ipcgb)
    64776504         ENDDO
     6505         !$OMP END DO
    64786506
    64796507         IF ( humidity .AND. plant_canopy_transpiration ) THEN
     
    64816509             pcm_transpiration_rate(:,:,:) = 0.0_wp
    64826510             pcm_latent_rate(:,:,:) = 0.0_wp
     6511             !$OMP DO PRIVATE (ipcgb, i, j, k, kk) SCHEDULE (STATIC)
    64836512             DO ipcgb = 1, npcbl
    64846513                 i = pcbl(ix, ipcgb)
     
    64906519                                                   pcm_transpiration_rate(kk,j,i),  &
    64916520                                                   pcm_latent_rate(kk,j,i) )
    6492               ENDDO
     6521             ENDDO
     6522             !$OMP END DO
    64936523         ENDIF
    64946524     ENDIF
     
    65066536!    and claculate relevant radiation model-RTM coupling terms
    65076537     mm = 1
     6538!--  following code depends on the order of the execution
     6539!--  do not parallelize by OpenMP
    65086540     DO  i = nxl, nxr
    65096541        DO  j = nys, nyn
     
    65986630     ENDDO
    65996631
     6632     !$OMP DO PRIVATE (i, d) REDUCTION(+:pabsswl, pabslwl, pemitlwl, pabs_surf_lwdifl) &
     6633     !$OMP&   SCHEDULE (STATIC)
    66006634     DO  i = 1, nsurfl
    66016635        d  = surfl(id, i)
     
    66126646                           emiss_surf(i) * facearea(d) * surfinlwdif(i)
    66136647     ENDDO
     6648     !$OMP END DO
    66146649
    66156650     DO l = 0, 1
     6651        !$OMP DO PRIVATE (m) SCHEDULE (STATIC)
    66166652        DO  m = 1, surf_usm_h(l)%ns
    66176653           surf_usm_h(l)%surfhf(m) = surf_usm_h(l)%rad_sw_in(m)  +          &
     
    66206656                                  surf_usm_h(l)%rad_lw_out(m)
    66216657        ENDDO
     6658        !$OMP END DO
     6659        !$OMP DO PRIVATE (m) SCHEDULE (STATIC)
    66226660        DO  m = 1, surf_lsm_h(l)%ns
    66236661           surf_lsm_h(l)%surfhf(m) = surf_lsm_h(l)%rad_sw_in(m)  +          &
     
    66266664                                  surf_lsm_h(l)%rad_lw_out(m)
    66276665        ENDDO
     6666        !$OMP END DO
    66286667     ENDDO
     6668
    66296669     DO  l = 0, 3
     6670        !$OMP DO PRIVATE (m) SCHEDULE (STATIC)
    66306671!--     urban
    66316672        DO  m = 1, surf_usm_v(l)%ns
     
    66356676                                     surf_usm_v(l)%rad_lw_out(m)
    66366677        ENDDO
     6678        !$OMP END DO
    66376679!--     land
     6680        !$OMP DO PRIVATE (m) SCHEDULE (STATIC)
    66386681        DO  m = 1, surf_lsm_v(l)%ns
    66396682           surf_lsm_v(l)%surfhf(m) = surf_lsm_v(l)%rad_sw_in(m)  +          &
     
    66436686
    66446687        ENDDO
     6688        !$OMP END DO
    66456689     ENDDO
    66466690!
Note: See TracChangeset for help on using the changeset viewer.