| 1 | #include "cppdefs.h"
|
|---|
| 2 | MODULE mod_parallel
|
|---|
| 3 | !
|
|---|
| 4 | !svn $Id: mod_parallel.F 29 2007-04-23 19:23:26Z arango $
|
|---|
| 5 | !================================================== Hernan G. Arango ===
|
|---|
| 6 | ! Copyright (c) 2002-2007 The ROMS/TOMS Group !
|
|---|
| 7 | ! Licensed under a MIT/X style license !
|
|---|
| 8 | ! See License_ROMS.txt !
|
|---|
| 9 | !=======================================================================
|
|---|
| 10 | ! !
|
|---|
| 11 | ! This module contains all variables used for parallelization !
|
|---|
| 12 | ! !
|
|---|
| 13 | !=======================================================================
|
|---|
| 14 | !
|
|---|
| 15 | USE mod_param
|
|---|
| 16 | USE mod_strings, ONLY: Nregion
|
|---|
| 17 | !
|
|---|
| 18 | implicit none
|
|---|
| 19 |
|
|---|
| 20 | #ifdef MPI
|
|---|
| 21 | include 'mpif.h'
|
|---|
| 22 | #endif
|
|---|
| 23 | !
|
|---|
| 24 | ! Switch to identify master processor. In serial and shared-memory
|
|---|
| 25 | ! applications it is always true.
|
|---|
| 26 | !
|
|---|
| 27 | logical :: Master
|
|---|
| 28 | !
|
|---|
| 29 | ! Switch to identify which thread is processing input/output files.
|
|---|
| 30 | ! In distributed-memory applications, this thread can be the master
|
|---|
| 31 | ! thread or all threads in case of parallel output. In serial and
|
|---|
| 32 | ! shared-memory applications it is always true.
|
|---|
| 33 | !
|
|---|
| 34 | logical :: InpThread
|
|---|
| 35 | logical :: OutThread
|
|---|
| 36 | !
|
|---|
| 37 | ! Number of shared-memory parallel threads. In distributed memory
|
|---|
| 38 | ! configurations, its value must be equal to one.
|
|---|
| 39 | !
|
|---|
| 40 | integer :: numthreads = 1
|
|---|
| 41 | !
|
|---|
| 42 | ! Number distributed memory nodes.
|
|---|
| 43 | !
|
|---|
| 44 | integer :: numnodes = 0
|
|---|
| 45 |
|
|---|
| 46 | #ifdef AIR_OCEAN
|
|---|
| 47 | !
|
|---|
| 48 | ! Parallel nodes assined to the atmosphere model.
|
|---|
| 49 | !
|
|---|
| 50 | integer :: peATM_frst ! first atmosphere parallel node
|
|---|
| 51 | integer :: peATM_last ! last atmosphere parallel node
|
|---|
| 52 | #endif
|
|---|
| 53 | #ifdef WAVES_OCEAN
|
|---|
| 54 | !
|
|---|
| 55 | ! Parallel nodes assined to the wave model.
|
|---|
| 56 | !
|
|---|
| 57 | integer :: peWAV_frst ! first atmosphere parallel node
|
|---|
| 58 | integer :: peWAV_last ! last atmosphere parallel node
|
|---|
| 59 | #endif
|
|---|
| 60 | !
|
|---|
| 61 | ! Parallel nodes assined to the ocean model.
|
|---|
| 62 | !
|
|---|
| 63 | integer :: peOCN_frst ! first ocean parallel node
|
|---|
| 64 | integer :: peOCN_last ! last ocean parallel node
|
|---|
| 65 | !
|
|---|
| 66 | ! Parallel threads/nodes counters used in critical parallel regions.
|
|---|
| 67 | !
|
|---|
| 68 | integer :: tile_count = 0
|
|---|
| 69 | integer :: block_count = 0
|
|---|
| 70 | integer :: thread_count = 0
|
|---|
| 71 | !
|
|---|
| 72 | ! Profiling variables as function of parallel thread:
|
|---|
| 73 | !
|
|---|
| 74 | ! proc Parallel process ID.
|
|---|
| 75 | ! Cstr Starting time for program region.
|
|---|
| 76 | ! Cend Ending time for program region.
|
|---|
| 77 | ! Csum Accumulated time for progam region.
|
|---|
| 78 | !
|
|---|
| 79 | integer :: proc(0:1,7,Ngrids)
|
|---|
| 80 |
|
|---|
| 81 | real(r8) :: Cstr(0:Nregion,7,Ngrids)
|
|---|
| 82 | real(r8) :: Cend(0:Nregion,7,Ngrids)
|
|---|
| 83 | real(r8) :: Csum(0:Nregion,7,Ngrids)
|
|---|
| 84 |
|
|---|
| 85 | #ifdef _OPENMP
|
|---|
| 86 | common /process/ proc
|
|---|
| 87 | !$OMP THREADPRIVATE (/process/)
|
|---|
| 88 |
|
|---|
| 89 | common /wallclock/ Cstr, Cend
|
|---|
| 90 | !$OMP THREADPRIVATE (/wallclock/)
|
|---|
| 91 | #endif
|
|---|
| 92 | !
|
|---|
| 93 | ! Distributed-memory master process and rank of the local process.
|
|---|
| 94 | !
|
|---|
| 95 | integer, parameter :: MyMaster = 0
|
|---|
| 96 | integer :: MyRank = 0
|
|---|
| 97 |
|
|---|
| 98 | #ifdef DISTRIBUTE
|
|---|
| 99 | # ifdef MPI
|
|---|
| 100 | !
|
|---|
| 101 | ! Ocean model MPI group communicator handle.
|
|---|
| 102 | !
|
|---|
| 103 | integer :: OCN_COMM_WORLD
|
|---|
| 104 | # endif
|
|---|
| 105 | !
|
|---|
| 106 | ! Type of message-passage floating point bindings.
|
|---|
| 107 | !
|
|---|
| 108 | # ifdef DOUBLE_PRECISION
|
|---|
| 109 | # ifdef MPI
|
|---|
| 110 | integer, parameter :: MP_FLOAT = MPI_DOUBLE_PRECISION
|
|---|
| 111 | !! integer, parameter :: MP_FLOAT = MPI_REAL8
|
|---|
| 112 | # endif
|
|---|
| 113 | # else
|
|---|
| 114 | # ifdef MPI
|
|---|
| 115 | integer, parameter :: MP_FLOAT = MPI_REAL
|
|---|
| 116 | !! integer, parameter :: MP_FLOAT = MPI_REAL4
|
|---|
| 117 | # endif
|
|---|
| 118 | # endif
|
|---|
| 119 | #endif
|
|---|
| 120 |
|
|---|
| 121 | CONTAINS
|
|---|
| 122 |
|
|---|
| 123 | SUBROUTINE initialize_parallel
|
|---|
| 124 | !
|
|---|
| 125 | !=======================================================================
|
|---|
| 126 | ! !
|
|---|
| 127 | ! This routine initializes and spawn distribute-memory nodes. !
|
|---|
| 128 | ! !
|
|---|
| 129 | !=======================================================================
|
|---|
| 130 | !
|
|---|
| 131 | USE mod_param
|
|---|
| 132 | USE mod_iounits
|
|---|
| 133 | USE mod_scalars
|
|---|
| 134 | USE mod_strings, ONLY: Nregion
|
|---|
| 135 | !
|
|---|
| 136 | ! Local variable declarations.
|
|---|
| 137 | !
|
|---|
| 138 | integer :: i
|
|---|
| 139 | #ifdef DISTRIBUTE
|
|---|
| 140 | integer :: MyError
|
|---|
| 141 | #endif
|
|---|
| 142 | #ifndef DISTRIBUTE
|
|---|
| 143 | integer :: my_numthreads
|
|---|
| 144 | !
|
|---|
| 145 | !-----------------------------------------------------------------------
|
|---|
| 146 | ! Initialize shared-memory (OpenMP) or serial configuration.
|
|---|
| 147 | !-----------------------------------------------------------------------
|
|---|
| 148 | !
|
|---|
| 149 | ! Inquire number of threads in parallel region.
|
|---|
| 150 | !
|
|---|
| 151 | numthreads=my_numthreads()
|
|---|
| 152 | Master=.TRUE.
|
|---|
| 153 | InpThread=.TRUE.
|
|---|
| 154 | OutThread=.TRUE.
|
|---|
| 155 | #endif
|
|---|
| 156 | #ifdef DISTRIBUTE
|
|---|
| 157 | # ifdef MPI
|
|---|
| 158 | !
|
|---|
| 159 | !-----------------------------------------------------------------------
|
|---|
| 160 | ! Initialize distributed-memory (MPI) configuration.
|
|---|
| 161 | !-----------------------------------------------------------------------
|
|---|
| 162 | !
|
|---|
| 163 | ! Get the number of processes in the group associated with the world
|
|---|
| 164 | ! communicator.
|
|---|
| 165 | !
|
|---|
| 166 | numthreads=1
|
|---|
| 167 | CALL mpi_comm_size (OCN_COMM_WORLD, numnodes, MyError)
|
|---|
| 168 | IF (MyError.ne.0) THEN
|
|---|
| 169 | WRITE (stdout,10)
|
|---|
| 170 | 10 FORMAT (/,' ROMS/TOMS - Unable to inquire number of', &
|
|---|
| 171 | & ' processors in the group.')
|
|---|
| 172 | exit_flag=6
|
|---|
| 173 | RETURN
|
|---|
| 174 | END IF
|
|---|
| 175 | !
|
|---|
| 176 | ! Identify master thread and output thread.
|
|---|
| 177 | !
|
|---|
| 178 | Master=.FALSE.
|
|---|
| 179 | InpThread=.FALSE.
|
|---|
| 180 | OutThread=.FALSE.
|
|---|
| 181 | IF (MyRank.eq.MyMaster) THEN
|
|---|
| 182 | Master=.TRUE.
|
|---|
| 183 | InpThread=.TRUE.
|
|---|
| 184 | OutThread=.TRUE.
|
|---|
| 185 | END IF
|
|---|
| 186 | # endif
|
|---|
| 187 | #endif
|
|---|
| 188 | !
|
|---|
| 189 | !-----------------------------------------------------------------------
|
|---|
| 190 | ! Initialize profiling variables.
|
|---|
| 191 | !-----------------------------------------------------------------------
|
|---|
| 192 | !
|
|---|
| 193 | proc(0:1,1:7,1:Ngrids)=0
|
|---|
| 194 | Cstr(0:Nregion,1:7,1:Ngrids)=0.0_r8
|
|---|
| 195 | Cend(0:Nregion,1:7,1:Ngrids)=0.0_r8
|
|---|
| 196 | Csum(0:Nregion,1:7,1:Ngrids)=0.0_r8
|
|---|
| 197 |
|
|---|
| 198 | RETURN
|
|---|
| 199 | END SUBROUTINE initialize_parallel
|
|---|
| 200 | END MODULE mod_parallel
|
|---|