1 | ! |
---|
2 | !$Id: mod_phys_lmdz_mpi_data.f90 5268 2024-10-23 17:02:39Z evignon $ |
---|
3 | ! |
---|
4 | MODULE mod_phys_lmdz_mpi_data |
---|
5 | USE lmdz_mpi |
---|
6 | USE lmdz_cppkeys_wrapper, ONLY: CPPKEY_INCA |
---|
7 | |
---|
8 | INTEGER,SAVE :: ii_begin |
---|
9 | INTEGER,SAVE :: ii_end |
---|
10 | INTEGER,SAVE :: jj_begin |
---|
11 | INTEGER,SAVE :: jj_end |
---|
12 | INTEGER,SAVE :: jj_nb |
---|
13 | INTEGER,SAVE :: ij_begin |
---|
14 | INTEGER,SAVE :: ij_end |
---|
15 | INTEGER,SAVE :: ij_nb |
---|
16 | INTEGER,SAVE :: klon_mpi_begin |
---|
17 | INTEGER,SAVE :: klon_mpi_end |
---|
18 | INTEGER,SAVE :: klon_mpi |
---|
19 | |
---|
20 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_nb |
---|
21 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_begin |
---|
22 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_end |
---|
23 | |
---|
24 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ii_para_begin |
---|
25 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ii_para_end |
---|
26 | |
---|
27 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_nb |
---|
28 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_begin |
---|
29 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_end |
---|
30 | |
---|
31 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_nb |
---|
32 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_begin |
---|
33 | INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_end |
---|
34 | |
---|
35 | |
---|
36 | INTEGER,SAVE :: mpi_rank |
---|
37 | INTEGER,SAVE :: mpi_size |
---|
38 | INTEGER,SAVE :: mpi_master |
---|
39 | LOGICAL,SAVE :: is_mpi_root |
---|
40 | LOGICAL,SAVE :: is_using_mpi |
---|
41 | |
---|
42 | |
---|
43 | LOGICAL,SAVE :: is_north_pole_dyn |
---|
44 | LOGICAL,SAVE :: is_south_pole_dyn |
---|
45 | INTEGER,SAVE :: COMM_LMDZ_PHY |
---|
46 | INTEGER,SAVE :: MPI_REAL_LMDZ ! MPI_REAL8 |
---|
47 | |
---|
48 | CONTAINS |
---|
49 | |
---|
50 | SUBROUTINE init_phys_lmdz_mpi_data(nbp, nbp_lon, nbp_lat, nbp_lev, grid_type, nvertex, communicator) |
---|
51 | USE lmdz_mpi |
---|
52 | IMPLICIT NONE |
---|
53 | INTEGER,INTENT(IN) :: nbp |
---|
54 | INTEGER,INTENT(IN) :: nbp_lon |
---|
55 | INTEGER,INTENT(IN) :: nbp_lat |
---|
56 | INTEGER,INTENT(IN) :: nbp_lev |
---|
57 | INTEGER,INTENT(IN) :: communicator |
---|
58 | INTEGER,INTENT(IN) :: grid_type |
---|
59 | INTEGER,INTENT(IN) :: nvertex |
---|
60 | |
---|
61 | INTEGER,ALLOCATABLE :: distrib(:) |
---|
62 | INTEGER :: ierr |
---|
63 | INTEGER :: klon_glo |
---|
64 | INTEGER :: i |
---|
65 | |
---|
66 | is_using_mpi = using_mpi |
---|
67 | |
---|
68 | if ((nbp_lon.eq.1).and.(nbp_lat.eq.1)) then ! running 1D column model |
---|
69 | klon_glo=1 |
---|
70 | else |
---|
71 | ! The usual global physics grid: 1 point for each pole and nbp_lon points |
---|
72 | ! for all other latitudes |
---|
73 | klon_glo=nbp_lon*(nbp_lat-2)+2 |
---|
74 | endif |
---|
75 | |
---|
76 | COMM_LMDZ_PHY=communicator |
---|
77 | |
---|
78 | IF (is_using_mpi) THEN |
---|
79 | MPI_REAL_LMDZ=MPI_REAL8 |
---|
80 | CALL MPI_COMM_SIZE(COMM_LMDZ_PHY,mpi_size,ierr) |
---|
81 | CALL MPI_COMM_RANK(COMM_LMDZ_PHY,mpi_rank,ierr) |
---|
82 | ELSE |
---|
83 | mpi_size=1 |
---|
84 | mpi_rank=0 |
---|
85 | ENDIF |
---|
86 | |
---|
87 | ALLOCATE(distrib(0:mpi_size-1)) |
---|
88 | |
---|
89 | IF (is_using_mpi) THEN |
---|
90 | CALL MPI_ALLGATHER(nbp,1,MPI_INTEGER,distrib,1,MPI_INTEGER,COMM_LMDZ_PHY,ierr) |
---|
91 | ELSE |
---|
92 | distrib(:)=nbp |
---|
93 | ENDIF |
---|
94 | |
---|
95 | |
---|
96 | IF (mpi_rank == 0) THEN |
---|
97 | mpi_master = 0 |
---|
98 | is_mpi_root = .true. |
---|
99 | ENDIF |
---|
100 | |
---|
101 | IF (mpi_rank == 0) THEN |
---|
102 | is_north_pole_dyn = .TRUE. |
---|
103 | ELSE |
---|
104 | is_north_pole_dyn = .FALSE. |
---|
105 | ENDIF |
---|
106 | |
---|
107 | IF (mpi_rank == mpi_size-1) THEN |
---|
108 | is_south_pole_dyn = .TRUE. |
---|
109 | ELSE |
---|
110 | is_south_pole_dyn = .FALSE. |
---|
111 | ENDIF |
---|
112 | |
---|
113 | ALLOCATE(jj_para_nb(0:mpi_size-1)) |
---|
114 | ALLOCATE(jj_para_begin(0:mpi_size-1)) |
---|
115 | ALLOCATE(jj_para_end(0:mpi_size-1)) |
---|
116 | |
---|
117 | ALLOCATE(ij_para_nb(0:mpi_size-1)) |
---|
118 | ALLOCATE(ij_para_begin(0:mpi_size-1)) |
---|
119 | ALLOCATE(ij_para_end(0:mpi_size-1)) |
---|
120 | |
---|
121 | ALLOCATE(ii_para_begin(0:mpi_size-1)) |
---|
122 | ALLOCATE(ii_para_end(0:mpi_size-1)) |
---|
123 | |
---|
124 | ALLOCATE(klon_mpi_para_nb(0:mpi_size-1)) |
---|
125 | ALLOCATE(klon_mpi_para_begin(0:mpi_size-1)) |
---|
126 | ALLOCATE(klon_mpi_para_end(0:mpi_size-1)) |
---|
127 | |
---|
128 | |
---|
129 | klon_mpi_para_nb(0:mpi_size-1)=distrib(0:mpi_size-1) |
---|
130 | |
---|
131 | DO i=0,mpi_size-1 |
---|
132 | IF (i==0) THEN |
---|
133 | klon_mpi_para_begin(i)=1 |
---|
134 | ELSE |
---|
135 | klon_mpi_para_begin(i)=klon_mpi_para_end(i-1)+1 |
---|
136 | ENDIF |
---|
137 | klon_mpi_para_end(i)=klon_mpi_para_begin(i)+klon_mpi_para_nb(i)-1 |
---|
138 | ENDDO |
---|
139 | |
---|
140 | |
---|
141 | DO i=0,mpi_size-1 |
---|
142 | |
---|
143 | IF (i==0) THEN |
---|
144 | ij_para_begin(i) = 1 |
---|
145 | ELSE |
---|
146 | ij_para_begin(i) = klon_mpi_para_begin(i)+nbp_lon-1 |
---|
147 | ENDIF |
---|
148 | |
---|
149 | jj_para_begin(i) = (ij_para_begin(i)-1)/nbp_lon + 1 |
---|
150 | ii_para_begin(i) = MOD(ij_para_begin(i)-1,nbp_lon) + 1 |
---|
151 | |
---|
152 | |
---|
153 | ij_para_end(i) = klon_mpi_para_end(i)+nbp_lon-1 |
---|
154 | jj_para_end(i) = (ij_para_end(i)-1)/nbp_lon + 1 |
---|
155 | ii_para_end(i) = MOD(ij_para_end(i)-1,nbp_lon) + 1 |
---|
156 | |
---|
157 | |
---|
158 | ij_para_nb(i) = ij_para_end(i)-ij_para_begin(i)+1 |
---|
159 | jj_para_nb(i) = jj_para_end(i)-jj_para_begin(i)+1 |
---|
160 | |
---|
161 | ENDDO |
---|
162 | |
---|
163 | ii_begin = ii_para_begin(mpi_rank) |
---|
164 | ii_end = ii_para_end(mpi_rank) |
---|
165 | jj_begin = jj_para_begin(mpi_rank) |
---|
166 | jj_end = jj_para_end(mpi_rank) |
---|
167 | jj_nb = jj_para_nb(mpi_rank) |
---|
168 | ij_begin = ij_para_begin(mpi_rank) |
---|
169 | ij_end = ij_para_end(mpi_rank) |
---|
170 | ij_nb = ij_para_nb(mpi_rank) |
---|
171 | klon_mpi_begin = klon_mpi_para_begin(mpi_rank) |
---|
172 | klon_mpi_end = klon_mpi_para_end(mpi_rank) |
---|
173 | klon_mpi = klon_mpi_para_nb(mpi_rank) |
---|
174 | |
---|
175 | CALL Print_module_data |
---|
176 | |
---|
177 | IF (CPPKEY_INCA) THEN |
---|
178 | CALL init_inca_para( & |
---|
179 | nbp_lon,nbp_lat,nbp_lev,klon_glo,mpi_size, & |
---|
180 | distrib,nvertex, grid_type,communicator) |
---|
181 | END IF |
---|
182 | |
---|
183 | END SUBROUTINE Init_phys_lmdz_mpi_data |
---|
184 | |
---|
185 | SUBROUTINE print_module_data |
---|
186 | USE print_control_mod, ONLY: lunout |
---|
187 | IMPLICIT NONE |
---|
188 | ! INCLUDE "iniprint.h" |
---|
189 | |
---|
190 | WRITE(lunout,*) 'ii_begin =', ii_begin |
---|
191 | WRITE(lunout,*) 'ii_end =', ii_end |
---|
192 | WRITE(lunout,*) 'jj_begin =',jj_begin |
---|
193 | WRITE(lunout,*) 'jj_end =', jj_end |
---|
194 | WRITE(lunout,*) 'jj_nb =', jj_nb |
---|
195 | WRITE(lunout,*) 'ij_begin =', ij_begin |
---|
196 | WRITE(lunout,*) 'ij_end =', ij_end |
---|
197 | WRITE(lunout,*) 'ij_nb =', ij_nb |
---|
198 | WRITE(lunout,*) 'klon_mpi_begin =', klon_mpi_begin |
---|
199 | WRITE(lunout,*) 'klon_mpi_end =', klon_mpi_end |
---|
200 | WRITE(lunout,*) 'klon_mpi =', klon_mpi |
---|
201 | WRITE(lunout,*) 'jj_para_nb =', jj_para_nb |
---|
202 | WRITE(lunout,*) 'jj_para_begin =', jj_para_begin |
---|
203 | WRITE(lunout,*) 'jj_para_end =', jj_para_end |
---|
204 | WRITE(lunout,*) 'ii_para_begin =', ii_para_begin |
---|
205 | WRITE(lunout,*) 'ii_para_end =', ii_para_end |
---|
206 | WRITE(lunout,*) 'ij_para_nb =', ij_para_nb |
---|
207 | WRITE(lunout,*) 'ij_para_begin =', ij_para_begin |
---|
208 | WRITE(lunout,*) 'ij_para_end =', ij_para_end |
---|
209 | WRITE(lunout,*) 'klon_mpi_para_nb =', klon_mpi_para_nb |
---|
210 | WRITE(lunout,*) 'klon_mpi_para_begin =', klon_mpi_para_begin |
---|
211 | WRITE(lunout,*) 'klon_mpi_para_end =', klon_mpi_para_end |
---|
212 | WRITE(lunout,*) 'mpi_rank =', mpi_rank |
---|
213 | WRITE(lunout,*) 'mpi_size =', mpi_size |
---|
214 | WRITE(lunout,*) 'mpi_master =', mpi_master |
---|
215 | WRITE(lunout,*) 'is_mpi_root =', is_mpi_root |
---|
216 | WRITE(lunout,*) 'is_north_pole =', is_north_pole_dyn |
---|
217 | WRITE(lunout,*) 'is_south_pole =', is_south_pole_dyn |
---|
218 | WRITE(lunout,*) 'COMM_LMDZ_PHY =', COMM_LMDZ_PHY |
---|
219 | |
---|
220 | END SUBROUTINE print_module_data |
---|
221 | |
---|
222 | END MODULE mod_phys_lmdz_mpi_data |
---|