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