New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 14537 for NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/DOM – NEMO

Ignore:
Timestamp:
2021-02-23T15:18:28+01:00 (3 years ago)
Author:
hadcv
Message:

#2600: Reorganise dom_tile code

Location:
NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/DOM
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/DOM/dom_oce.F90

    r14223 r14537  
    7878   INTEGER         ::   nn_ltile_i, nn_ltile_j 
    7979 
    80    ! Domain tiling (all tiles) 
     80   ! Domain tiling 
    8181   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ntsi_a       !: start of internal part of tile domain 
    8282   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ntsj_a       ! 
    8383   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ntei_a       !: end of internal part of tile domain 
    8484   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ntej_a       ! 
     85   LOGICAL, PUBLIC                                  ::   l_istiled    ! whether tiling is currently active or not 
    8586 
    8687   !                             !: domain MPP decomposition parameters 
  • NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/DOM/domain.F90

    r14255 r14537  
    133133      !           !==  Reference coordinate system  ==! 
    134134      ! 
    135       CALL dom_glo                            ! global domain versus local domain 
    136       CALL dom_nam                            ! read namelist ( namrun, namdom ) 
    137       CALL dom_tile( ntsi, ntsj, ntei, ntej ) ! Tile domain 
     135      CALL dom_glo                      ! global domain versus local domain 
     136      CALL dom_nam                      ! read namelist ( namrun, namdom ) 
     137      CALL dom_tile_init                ! Tile domain 
    138138 
    139139      ! 
  • NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/DOM/domtile.F90

    r14090 r14537  
    1313   ! 
    1414   USE prtctl         ! Print control (prt_ctl_info routine) 
     15   USE lib_mpp , ONLY : ctl_stop, ctl_warn 
    1516   USE in_out_manager ! I/O manager 
    1617 
     
    1819   PRIVATE 
    1920 
    20    PUBLIC dom_tile   ! called by step.F90 
     21   PUBLIC dom_tile         ! called by step.F90 
     22   PUBLIC dom_tile_start   ! called by various 
     23   PUBLIC dom_tile_stop    ! "      " 
     24   PUBLIC dom_tile_init    ! called by domain.F90 
     25 
     26   LOGICAL, ALLOCATABLE, DIMENSION(:) ::   l_tilefin    ! whether a tile is finished or not 
    2127 
    2228   !!---------------------------------------------------------------------- 
     
    2733CONTAINS 
    2834 
    29    SUBROUTINE dom_tile( ktsi, ktsj, ktei, ktej, ktile ) 
     35   SUBROUTINE dom_tile_init 
     36      !!---------------------------------------------------------------------- 
     37      !!                     ***  ROUTINE dom_tile_init  *** 
     38      !! 
     39      !! ** Purpose :   Initialise tile domain variables 
     40      !! 
     41      !! ** Action  : - ntsi, ntsj     : start of internal part of domain 
     42      !!              - ntei, ntej     : end of internal part of domain 
     43      !!              - ntile          : current tile number 
     44      !!              - nijtile        : total number of tiles 
     45      !!              - nthl, nthr     : modifier on DO loop macro bound offset (left, right) 
     46      !!              - nthb, ntht     :              "         "               (bottom, top) 
     47      !!              - l_istiled      : whether tiling is currently active or not 
     48      !!              - l_tilefin      : whether a tile is finished or not 
     49      !!---------------------------------------------------------------------- 
     50      INTEGER ::   jt                                     ! dummy loop argument 
     51      INTEGER ::   iitile, ijtile                         ! Local integers 
     52      !!---------------------------------------------------------------------- 
     53      ntile = 0                     ! Initialise to full domain 
     54      nijtile = 1 
     55      ntsi = Nis0 
     56      ntsj = Njs0 
     57      ntei = Nie0 
     58      ntej = Nje0 
     59      nthl = 0 
     60      nthr = 0 
     61      nthb = 0 
     62      ntht = 0 
     63      l_istiled = .FALSE. 
     64 
     65      IF( ln_tile ) THEN            ! Calculate tile domain indices 
     66         iitile = Ni_0 / nn_ltile_i       ! Number of tiles 
     67         ijtile = Nj_0 / nn_ltile_j 
     68         IF( MOD( Ni_0, nn_ltile_i ) /= 0 ) iitile = iitile + 1 
     69         IF( MOD( Nj_0, nn_ltile_j ) /= 0 ) ijtile = ijtile + 1 
     70 
     71         nijtile = iitile * ijtile 
     72         ALLOCATE( ntsi_a(0:nijtile), ntsj_a(0:nijtile), ntei_a(0:nijtile), ntej_a(0:nijtile), l_tilefin(nijtile) ) 
     73 
     74         l_tilefin(:) = .FALSE. 
     75 
     76         ntsi_a(0) = Nis0                 ! Full domain 
     77         ntsj_a(0) = Njs0 
     78         ntei_a(0) = Nie0 
     79         ntej_a(0) = Nje0 
     80 
     81         DO jt = 1, nijtile               ! Tile domains 
     82            ntsi_a(jt) = Nis0 + nn_ltile_i * MOD(jt - 1, iitile) 
     83            ntsj_a(jt) = Njs0 + nn_ltile_j * ((jt - 1) / iitile) 
     84            ntei_a(jt) = MIN(ntsi_a(jt) + nn_ltile_i - 1, Nie0) 
     85            ntej_a(jt) = MIN(ntsj_a(jt) + nn_ltile_j - 1, Nje0) 
     86         ENDDO 
     87      ENDIF 
     88 
     89      IF(lwp) THEN                  ! control print 
     90         WRITE(numout,*) 
     91         WRITE(numout,*) 'dom_tile : Domain tiling decomposition' 
     92         WRITE(numout,*) '~~~~~~~~' 
     93         IF( ln_tile ) THEN 
     94            WRITE(numout,*) iitile, 'tiles in i' 
     95            WRITE(numout,*) '    Starting indices' 
     96            WRITE(numout,*) '        ', (ntsi_a(jt), jt=1, iitile) 
     97            WRITE(numout,*) '    Ending indices' 
     98            WRITE(numout,*) '        ', (ntei_a(jt), jt=1, iitile) 
     99            WRITE(numout,*) ijtile, 'tiles in j' 
     100            WRITE(numout,*) '    Starting indices' 
     101            WRITE(numout,*) '        ', (ntsj_a(jt), jt=1, nijtile, iitile) 
     102            WRITE(numout,*) '    Ending indices' 
     103            WRITE(numout,*) '        ', (ntej_a(jt), jt=1, nijtile, iitile) 
     104         ELSE 
     105            WRITE(numout,*) 'No domain tiling' 
     106            WRITE(numout,*) '    i indices =', ntsi, ':', ntei 
     107            WRITE(numout,*) '    j indices =', ntsj, ':', ntej 
     108         ENDIF 
     109      ENDIF 
     110   END SUBROUTINE dom_tile_init 
     111 
     112 
     113   SUBROUTINE dom_tile( ktsi, ktsj, ktei, ktej, ktile, ldhold, cstr ) 
    30114      !!---------------------------------------------------------------------- 
    31115      !!                     ***  ROUTINE dom_tile  *** 
    32116      !! 
    33       !! ** Purpose :   Set tile domain variables 
     117      !! ** Purpose :   Set the current tile and its domain indices 
    34118      !! 
    35119      !! ** Action  : - ktsi, ktsj     : start of internal part of domain 
    36120      !!              - ktei, ktej     : end of internal part of domain 
    37       !!              - ntile          : current tile number 
    38       !!              - nijtile        : total number of tiles 
     121      !!              - nthl, nthr     : modifier on DO loop macro bound offset (left, right) 
     122      !!              - nthb, ntht     :              "         "               (bottom, top) 
     123      !!              - ktile          : set the current tile number (ntile) 
    39124      !!---------------------------------------------------------------------- 
    40125      INTEGER, INTENT(out) :: ktsi, ktsj, ktei, ktej      ! Tile domain indices 
    41       INTEGER, INTENT(in), OPTIONAL :: ktile              ! Tile number 
    42       INTEGER ::   jt                                     ! dummy loop argument 
    43       INTEGER ::   iitile, ijtile                         ! Local integers 
    44       CHARACTER (len=11) ::   charout 
    45       !!---------------------------------------------------------------------- 
    46       IF( PRESENT(ktile) .AND. ln_tile ) THEN 
    47          ntile = ktile                 ! Set domain indices for tile 
    48          ktsi = ntsi_a(ktile) 
    49          ktsj = ntsj_a(ktile) 
    50          ktei = ntei_a(ktile) 
    51          ktej = ntej_a(ktile) 
    52  
     126      INTEGER, INTENT(in)  :: ktile                       ! Tile number 
     127      LOGICAL, INTENT(in), OPTIONAL :: ldhold             ! Pause/resume (.true.) or set (.false.) current tile 
     128      ! TEMP: [tiling] DEBUG 
     129      CHARACTER(len=*), INTENT(in), OPTIONAL   :: cstr 
     130      CHARACTER(len=23) :: clstr 
     131      LOGICAL :: llhold 
     132      CHARACTER(len=11)   :: charout 
     133      !!---------------------------------------------------------------------- 
     134      llhold = .FALSE. 
     135      IF( PRESENT(ldhold) ) llhold = ldhold 
     136      clstr = '' 
     137      IF( PRESENT(cstr) ) clstr = TRIM(' ('//TRIM(cstr)//')') 
     138 
     139      IF( .NOT. ln_tile ) CALL ctl_stop('Cannot use dom_tile with ln_tile = .false.') 
     140      IF( .NOT. llhold ) THEN 
     141         IF( .NOT. l_istiled ) THEN 
     142            CALL ctl_warn('Cannot call dom_tile when tiling is inactive'//clstr) 
     143            RETURN 
     144         ENDIF 
     145 
     146         IF( ntile /= 0 ) l_tilefin(ntile) = .TRUE.         ! If setting a new tile, the current tile is complete 
     147 
     148         ntile = ktile                                      ! Set the new tile 
    53149         IF(sn_cfctl%l_prtctl) THEN 
    54             WRITE(charout, FMT="('ntile =', I4)") ktile 
     150            WRITE(charout, FMT="('ntile =', I4)") ntile 
    55151            CALL prt_ctl_info( charout ) 
    56152         ENDIF 
    57       ELSE 
    58          ntile = 0                     ! Initialise to full domain 
    59          nijtile = 1 
    60          ktsi = Nis0 
    61          ktsj = Njs0 
    62          ktei = Nie0 
    63          ktej = Nje0 
    64  
    65          IF( ln_tile ) THEN            ! Calculate tile domain indices 
    66             iitile = Ni_0 / nn_ltile_i       ! Number of tiles 
    67             ijtile = Nj_0 / nn_ltile_j 
    68             IF( MOD( Ni_0, nn_ltile_i ) /= 0 ) iitile = iitile + 1 
    69             IF( MOD( Nj_0, nn_ltile_j ) /= 0 ) ijtile = ijtile + 1 
    70  
    71             nijtile = iitile * ijtile 
    72             ALLOCATE( ntsi_a(0:nijtile), ntsj_a(0:nijtile), ntei_a(0:nijtile), ntej_a(0:nijtile) ) 
    73  
    74             ntsi_a(0) = ktsi                 ! Full domain 
    75             ntsj_a(0) = ktsj 
    76             ntei_a(0) = ktei 
    77             ntej_a(0) = ktej 
    78  
    79             DO jt = 1, nijtile               ! Tile domains 
    80                ntsi_a(jt) = Nis0 + nn_ltile_i * MOD(jt - 1, iitile) 
    81                ntsj_a(jt) = Njs0 + nn_ltile_j * ((jt - 1) / iitile) 
    82                ntei_a(jt) = MIN(ntsi_a(jt) + nn_ltile_i - 1, Nie0) 
    83                ntej_a(jt) = MIN(ntsj_a(jt) + nn_ltile_j - 1, Nje0) 
    84             ENDDO 
    85          ENDIF 
    86  
    87          IF(lwp) THEN                  ! control print 
    88             WRITE(numout,*) 
    89             WRITE(numout,*) 'dom_tile : Domain tiling decomposition' 
    90             WRITE(numout,*) '~~~~~~~~' 
    91             IF( ln_tile ) THEN 
    92                WRITE(numout,*) iitile, 'tiles in i' 
    93                WRITE(numout,*) '    Starting indices' 
    94                WRITE(numout,*) '        ', (ntsi_a(jt), jt=1, iitile) 
    95                WRITE(numout,*) '    Ending indices' 
    96                WRITE(numout,*) '        ', (ntei_a(jt), jt=1, iitile) 
    97                WRITE(numout,*) ijtile, 'tiles in j' 
    98                WRITE(numout,*) '    Starting indices' 
    99                WRITE(numout,*) '        ', (ntsj_a(jt), jt=1, nijtile, iitile) 
    100                WRITE(numout,*) '    Ending indices' 
    101                WRITE(numout,*) '        ', (ntej_a(jt), jt=1, nijtile, iitile) 
    102             ELSE 
    103                WRITE(numout,*) 'No domain tiling' 
    104                WRITE(numout,*) '    i indices =', ktsi, ':', ktei 
    105                WRITE(numout,*) '    j indices =', ktsj, ':', ktej 
    106             ENDIF 
    107          ENDIF 
    108       ENDIF 
     153      ENDIF 
     154 
     155      ktsi = ntsi_a(ktile)                                  ! Set the domain indices 
     156      ktsj = ntsj_a(ktile) 
     157      ktei = ntei_a(ktile) 
     158      ktej = ntej_a(ktile) 
     159 
     160      ! Calculate the modifying factor on DO loop bounds (1 = do not work on halo of a tile that has already been processed) 
     161      nthl = 0 ; nthr = 0 ; nthb = 0 ; ntht = 0 
     162      IF( ktsi > Nis0 ) THEN ; IF( l_tilefin(ktile - 1         ) ) nthl = 1 ; ENDIF    ! Left adjacent tile 
     163      IF( ktei < Nie0 ) THEN ; IF( l_tilefin(ktile + 1         ) ) nthr = 1 ; ENDIF    ! Right  "  " 
     164      IF( ktsj > Njs0 ) THEN ; IF( l_tilefin(ktile - nn_ltile_i) ) nthb = 1 ; ENDIF    ! Bottom "  " 
     165      IF( ktej < Nje0 ) THEN ; IF( l_tilefin(ktile + nn_ltile_i) ) ntht = 1 ; ENDIF    ! Top    "  " 
    109166   END SUBROUTINE dom_tile 
    110167 
     168 
     169   SUBROUTINE dom_tile_start( ldhold, cstr ) 
     170      !!---------------------------------------------------------------------- 
     171      !!                     ***  ROUTINE dom_tile_start  *** 
     172      !! 
     173      !! ** Purpose : Start or resume the use of tiling 
     174      !! 
     175      !! ** Method  : dom_tile_start & dom_tile_stop are used to declare a tiled region of code. 
     176      !! 
     177      !!              Tiling is active/inactive (l_istiled = .true./.false.) within/outside of this code region. 
     178      !!              After enabling tiling, no tile will initially be set (the full domain will be used) and dom_tile must 
     179      !!              be called to set a specific tile to work on. Furthermore, all tiles will be marked as incomplete 
     180      !!              (ln_tilefin(:) = .false.). 
     181      !! 
     182      !!              Tiling can be paused/resumed within the tiled code region by calling dom_tile_stop/dom_tile_start 
     183      !!              with ldhold = .true.. This can be used to temporarily revert back to using the full domain. 
     184      !! 
     185      !!                 CALL dom_tile_start                                  ! Enable tiling 
     186      !!                    CALL dom_tile(ntsi, ntei, ntsj, ntej, ktile=n)    ! Set current tile "n" 
     187      !!                    ... 
     188      !!                    CALL dom_tile_stop(.TRUE.)                        ! Pause tiling (temporarily disable) 
     189      !!                    ... 
     190      !!                    CALL dom_tile_start(.TRUE.)                       ! Resume tiling 
     191      !!                 CALL dom_tile_stop                                   ! Disable tiling 
     192      !!---------------------------------------------------------------------- 
     193      LOGICAL, INTENT(in), OPTIONAL :: ldhold      ! Resume (.true.) or start (.false.) 
     194      LOGICAL :: llhold 
     195      ! TEMP: [tiling] DEBUG 
     196      CHARACTER(len=*), INTENT(in), OPTIONAL   :: cstr 
     197      CHARACTER(len=23) :: clstr 
     198      !!---------------------------------------------------------------------- 
     199      llhold = .FALSE. 
     200      IF( PRESENT(ldhold) ) llhold = ldhold 
     201      clstr = '' 
     202      IF( PRESENT(cstr) ) clstr = TRIM(' ('//TRIM(cstr)//')') 
     203 
     204      IF( .NOT. ln_tile ) CALL ctl_stop('Cannot resume/start tiling as ln_tile = .false.') 
     205      IF( l_istiled ) THEN 
     206         CALL ctl_warn('Cannot resume/start tiling as it is already active'//clstr) 
     207         RETURN 
     208      ! TODO: This warning will always be raised outside a tiling loop (cannot check for pause rather than stop) 
     209      ELSE IF( llhold .AND. ntile == 0 ) THEN 
     210         CALL ctl_warn('Cannot resume tiling as it is not paused'//clstr) 
     211         RETURN 
     212      ENDIF 
     213 
     214      ! Whether resumed or started, the tiling is made active. If resumed, the domain indices for the current tile are used. 
     215      IF( llhold ) CALL dom_tile(ntsi, ntsj, ntei, ntej, ktile=ntile, ldhold=.TRUE., cstr='dom_tile_start'//clstr) 
     216      l_istiled = .TRUE. 
     217   END SUBROUTINE dom_tile_start 
     218 
     219 
     220   SUBROUTINE dom_tile_stop( ldhold, cstr ) 
     221      !!---------------------------------------------------------------------- 
     222      !!                     ***  ROUTINE dom_tile_stop  *** 
     223      !! 
     224      !! ** Purpose : End or pause the use of tiling 
     225      !! 
     226      !! ** Method  : See dom_tile_start 
     227      !!---------------------------------------------------------------------- 
     228      LOGICAL, INTENT(in), OPTIONAL :: ldhold      ! Pause (.true.) or stop (.false.) 
     229      LOGICAL :: llhold 
     230      ! TEMP: [tiling] DEBUG 
     231      CHARACTER(len=*), INTENT(in), OPTIONAL   :: cstr 
     232      CHARACTER(len=23) :: clstr 
     233      !!---------------------------------------------------------------------- 
     234      llhold = .FALSE. 
     235      IF( PRESENT(ldhold) ) llhold = ldhold 
     236      clstr = '' 
     237      IF( PRESENT(cstr) ) clstr = TRIM(' ('//TRIM(cstr)//')') 
     238 
     239      IF( .NOT. ln_tile ) CALL ctl_stop('Cannot pause/stop tiling as ln_tile = .false.') 
     240      IF( .NOT. l_istiled ) THEN 
     241         CALL ctl_warn('Cannot pause/stop tiling as it is inactive'//clstr) 
     242         RETURN 
     243      ENDIF 
     244 
     245      ! Whether paused or stopped, the tiling is made inactive and the full domain indices are used. 
     246      ! If stopped, there is no active tile (ntile = 0) and the finished tile indicators are reset 
     247      CALL dom_tile(ntsi, ntsj, ntei, ntej, ktile=0, ldhold=llhold, cstr='dom_tile_stop'//clstr) 
     248      IF( .NOT. llhold ) l_tilefin(:) = .FALSE. 
     249      l_istiled = .FALSE. 
     250   END SUBROUTINE dom_tile_stop 
    111251   !!====================================================================== 
    112252END MODULE domtile 
  • NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/DOM/dtatsd.F90

    r14189 r14537  
    141141      INTEGER ::   ji, jj, jk, jl, jkk   ! dummy loop indicies 
    142142      INTEGER ::   ik, il0, il1, ii0, ii1, ij0, ij1   ! local integers 
    143       INTEGER ::   itile 
    144143      INTEGER, DIMENSION(jpts), SAVE :: irec_b, irec_n 
    145144      REAL(wp)::   zl, zi                             ! local scalars 
     
    147146      !!---------------------------------------------------------------------- 
    148147      ! 
    149       IF( ntile == 0 .OR. ntile == 1 )  THEN                                         ! Do only for the full domain 
    150          itile = ntile 
    151          IF( ln_tile ) CALL dom_tile( ntsi, ntsj, ntei, ntej, ktile = 0 )            ! Use full domain 
     148      IF( .NOT. l_istiled .OR. ntile == 1 )  THEN                                         ! Do only for the full domain 
     149         IF( ln_tile ) CALL dom_tile_stop( ldhold=.TRUE., cstr='dtatsd' )             ! Use full domain 
    152150            CALL fld_read( kt, 1, sf_tsd )   !==   read T & S data at kt time step   ==! 
    153151      ! 
     
    195193         ENDIF 
    196194!!gm end 
    197          IF( ln_tile ) CALL dom_tile( ntsi, ntsj, ntei, ntej, ktile = itile )            ! Revert to tile domain 
     195         IF( ln_tile ) CALL dom_tile_start( ldhold=.TRUE., cstr='dtatsd' )            ! Revert to tile domain 
    198196      ENDIF 
    199197      ! 
     
    205203      IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==! 
    206204         ! 
    207          IF( ntile == 0 .OR. ntile == 1 )  THEN                       ! Do only on the first tile 
     205         IF( .NOT. l_istiled .OR. ntile == 1 )  THEN                       ! Do only on the first tile 
    208206            IF( kt == nit000 .AND. lwp )THEN 
    209207               WRITE(numout,*) 
Note: See TracChangeset for help on using the changeset viewer.