forked from NordicESMhub/OsloCTM3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomp.f90
309 lines (275 loc) · 10.5 KB
/
omp.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
!//=========================================================================
!// Oslo CTM3
!//=========================================================================
!// Based on UCI CTM core p-7.1 (1/2013).
!//
!// Ole Amund Sovde, March 2015
!//=========================================================================
!// OpenMP related routines.
!//=========================================================================
module omp
!//-----------------------------------------------------------------------
!// MODULE: omp
!// DESCRIPTION: Routnes for OpenMP.
!//
!// Contains:
!// - subroutine MPSPLIT
!// - subroutine MPBIND
!// - subroutine get_iijjmp
!// - subroutine get_all_mpind
!//-----------------------------------------------------------------------
implicit none
!//-----------------------------------------------------------------------
contains
!//-----------------------------------------------------------------------
subroutine MPSPLIT(BTT,BXT,BXX,BYT,BYY,BZT,BZZ,BXY,BXZ,BYZ, &
BTTTND,BTTBCK,AIRB,BTEM,GAMAB,LSTRATAIR_E90B,MP)
!//---------------------------------------------------------------------
!// Splits global arrays into private B-arrays.
!//---------------------------------------------------------------------
use cmn_precision, only: r8, rMom, rTnd
use cmn_size, only: LPAR, NPAR, IDBLK, JDBLK
use cmn_ctm, only: MPBLKIB, MPBLKIE, MPBLKJB, MPBLKJE, &
AIR, STT, SUT, SVT, SWT, SUU, SVV, SWW, SUV, SUW, SVW, &
GAMA
use cmn_chem, only: LSTRATAIR_E90
use cmn_diag, only: NTDPAR
use cmn_met, only: T
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
real(r8), intent(out), dimension(LPAR,IDBLK,JDBLK) :: AIRB, BTEM, GAMAB
real(r8), intent(out), dimension(LPAR,NPAR,IDBLK,JDBLK) :: BTT, BTTBCK
real(rTnd), intent(out), dimension(LPAR,NPAR,IDBLK,JDBLK,NTDPAR) :: &
BTTTND
real(rMom), intent(out), dimension(LPAR,NPAR,IDBLK,JDBLK) :: &
BXT, BXX, BYT, BYY, BZT, BZZ, BXY, BXZ, BYZ
logical, intent(out), dimension(LPAR,IDBLK,JDBLK) :: LSTRATAIR_E90B
integer, intent(in) :: MP
integer :: N, L, I, J, II, JJ, I1, I2, J1, J2
!//---------------------------------------------------------------------
J1 = MPBLKJB(MP)
J2 = MPBLKJE(MP)
I1 = MPBLKIB(MP)
I2 = MPBLKIE(MP)
do L = 1, LPAR
do J = J1, J2
JJ = J - J1 + 1
do I = I1, I2
II = I - I1 + 1
GAMAB(L,II,JJ) = GAMA(I,J,L)
AIRB(L,II,JJ) = AIR(I,J,L)
BTEM(L,II,JJ) = T(I,J,L)
end do
end do
end do
do J = MPBLKJB(MP), MPBLKJE(MP)
JJ = J - MPBLKJB(MP) + 1
do I = MPBLKIB(MP), MPBLKIE(MP)
II = I - MPBLKIB(MP) + 1
do L = 1, LPAR
LSTRATAIR_E90B(L,II,JJ) = LSTRATAIR_E90(L,I,J)
end do
end do
end do
do N = 1, NPAR
do L = 1, LPAR
do J = J1, J2
JJ = J - J1 + 1
do I = I1, I2
II = I - I1 + 1
BTT(L,N,II,JJ) = STT(I,J,L,N)
BTTBCK(L,N,II,JJ) = STT(I,J,L,N)
BXT(L,N,II,JJ) = SUT(I,J,L,N)
BXX(L,N,II,JJ) = SUU(I,J,L,N)
BYT(L,N,II,JJ) = SVT(I,J,L,N)
BYY(L,N,II,JJ) = SVV(I,J,L,N)
BZT(L,N,II,JJ) = SWT(I,J,L,N)
BZZ(L,N,II,JJ) = SWW(I,J,L,N)
BXY(L,N,II,JJ) = SUV(I,J,L,N)
BXZ(L,N,II,JJ) = SUW(I,J,L,N)
BYZ(L,N,II,JJ) = SVW(I,J,L,N)
end do
end do
end do
end do
BTTTND(:,:,:,:,:) = 0._rTnd
!//---------------------------------------------------------------------
end subroutine MPSPLIT
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine MPBIND(BTT,BXT,BXX,BYT,BYY,BZT,BZZ,BXY,BXZ,BYZ, &
BTTTND,AIRB,LSTRATAIR_E90B,MP)
!//---------------------------------------------------------------------
!// Puts private B-arrays back into global arrays.
!//---------------------------------------------------------------------
use cmn_precision, only: r8, rMom, rTnd
use cmn_size, only: LPAR, NPAR, NTDPAR, IDBLK, JDBLK
use cmn_ctm, only: MPBLKIB, MPBLKIE, MPBLKJB, MPBLKJE, &
AIR, STT, SUT, SVT, SWT, SUU, SVV, SWW, SUV, SUW, SVW
use cmn_diag, only: NTND, STTBCK, STTTND
use cmn_chem, only: LSTRATAIR_E90
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
real(r8), intent(in), dimension(LPAR,NPAR,IDBLK,JDBLK) :: BTT
real(r8), intent(in), dimension(LPAR,IDBLK,JDBLK) :: AIRB
real(rTnd), intent(in), dimension(LPAR,NPAR,IDBLK,JDBLK,NTDPAR) :: &
BTTTND
real(rMom), intent(in), dimension(LPAR,NPAR,IDBLK,JDBLK) :: &
BXT, BXX, BYT, BYY, BZT, BZZ, BXY, BXZ, BYZ
logical, intent(in), dimension(LPAR,IDBLK,JDBLK) :: LSTRATAIR_E90B
integer, intent(in) :: MP
integer :: N, L, I, J, II, JJ, M
integer :: K, NM, JS, J1, J2, I1, I2, II1, II2
!//---------------------------------------------------------------------
J1 = MPBLKJB(MP)
J2 = MPBLKJE(MP)
I1 = MPBLKIB(MP)
I2 = MPBLKIE(MP)
do N = 1,NPAR
do L = 1,LPAR
do J = J1, J2
JJ = J - J1 + 1
do I = I1, I2
II = I - I1 + 1
!// Assumes tendency cleared and logged to some process
STTBCK(I,J,L,N) = BTT(L,N,II,JJ)
STT(I,J,L,N) = BTT(L,N,II,JJ)
SUT(I,J,L,N) = BXT(L,N,II,JJ)
SUU(I,J,L,N) = BXX(L,N,II,JJ)
SVT(I,J,L,N) = BYT(L,N,II,JJ)
SVV(I,J,L,N) = BYY(L,N,II,JJ)
SWT(I,J,L,N) = BZT(L,N,II,JJ)
SWW(I,J,L,N) = BZZ(L,N,II,JJ)
SUV(I,J,L,N) = BXY(L,N,II,JJ)
SUW(I,J,L,N) = BXZ(L,N,II,JJ)
SVW(I,J,L,N) = BYZ(L,N,II,JJ)
end do
end do
end do
end do
!// M is outer index
do M = 1, NTND
do N = 1, NPAR
do L = 1, LPAR
do J = J1, J2
JJ = J - J1 + 1
do I = I1, I2
II = I - I1 + 1
STTTND(I,J,L,N,M) = STTTND(I,J,L,N,M) + BTTTND(L,N,II,JJ,M)
end do
end do
end do
end do
end do
do L = 1, LPAR
do J = J1, J2
JJ = J - J1 + 1
do I = I1, I2
II = I - I1 + 1
AIR(I,J,L) = AIRB(L,II,JJ)
end do
end do
end do
do J = J1, J2
JJ = J - J1 + 1
do I = I1, I2
II = I - I1 + 1
do L = 1, LPAR
LSTRATAIR_E90(L,I,J) = LSTRATAIR_E90B(L,II,JJ)
end do
end do
end do
!//---------------------------------------------------------------------
end subroutine MPBIND
!//-----------------------------------------------------------------------
!// ----------------------------------------------------------------------
subroutine get_iijjmp(iget,jget,ii,jj,mp)
!// --------------------------------------------------------------------
!// Send in global indices iget,jget, and get the MP-block indices.
!//
!// Ole Amund Sovde, February 2011
!// --------------------------------------------------------------------
use cmn_size, only: MPBLK
use cmn_ctm, only: MPBLKJB,MPBLKJE, MPBLKIB,MPBLKIE
!// --------------------------------------------------------------------
implicit none
!// --------------------------------------------------------------------
!// Input
integer, intent(in) :: iget, jget
!// Output
integer, intent(out) :: ii,jj,mp
!// Locals
integer :: I,J
logical :: foundII, foundJJ
!// ------------------------------------------------------------------
!// Only necessary to initialize foundII once
foundII = .false.
do MP = 1, MPBLK
!// Should initialize foundJJ each MP.
foundJJ = .false.
!// Check first for J. Then check if also I is in the current MP.
!// When both are found, we are at the correct MP.
do J = MPBLKJB(MP),MPBLKJE(MP)
JJ = J - MPBLKJB(MP) + 1
!// Found J
if (J == jget) then
foundJJ = .true.
exit
end if
end do
do I = MPBLKIB(MP),MPBLKIE(MP)
II = I - MPBLKIB(MP) + 1
!// Found I
if (foundJJ .and. I == iget) then
foundII = .true.
exit
end if
end do
!// When we have I and J, we have MP
if (foundJJ .and. foundII) exit
end do
if (.not.foundJJ .or. .not.foundII) then
!// This should never happen
print*,'utilities_oslo.f90: get_iijjmp: Cannot find II/JJ',iget,jget
print*,'II/JJ/MP:',ii,jj,mp
stop
end if
!// --------------------------------------------------------------------
end subroutine get_iijjmp
!// ----------------------------------------------------------------------
!// ----------------------------------------------------------------------
subroutine get_all_mpind()
!// --------------------------------------------------------------------
!// Find all MP-block indices as function of all i,j.
!//
!// Ole Amund Sovde, July 2011
!// --------------------------------------------------------------------
use cmn_size, only: MPBLK
use cmn_ctm, only: MPBLKJB,MPBLKJE, MPBLKIB,MPBLKIE, &
all_mp_indices
!// --------------------------------------------------------------------
implicit none
!// --------------------------------------------------------------------
!// Locals
integer :: I,J,MP,II,JJ
!// --------------------------------------------------------------------
do MP = 1, MPBLK
do J = MPBLKJB(MP), MPBLKJE(MP)
JJ = J - MPBLKJB(MP) + 1
do I = MPBLKIB(MP), MPBLKIE(MP)
II = I - MPBLKIB(MP) + 1
all_mp_indices(1,i,j) = II
all_mp_indices(2,i,j) = JJ
all_mp_indices(3,i,j) = MP
end do
end do
end do
!// --------------------------------------------------------------------
end subroutine get_all_mpind
!// ----------------------------------------------------------------------
!//-----------------------------------------------------------------------
end module omp
!//=========================================================================