@@ -56,33 +56,22 @@ function ghost_points_u_nonperiodic!(C::Constants,u::AbstractMatrix)
56
56
end
57
57
58
58
""" Copy ghost points for u from inside to the halo in the periodic case. """
59
- function ghost_points_u_periodic! (C :: Constants ,u:: AbstractMatrix )
59
+ function ghost_points_u_periodic! (:: Type{Tcomm} ,u:: Array{T,2} ,C :: Constants ) where {Tcomm,T}
60
60
61
61
@unpack one_minus_α = C
62
62
63
- # periodic bc
64
- @views @inbounds u[1 ,:] .= u[end - 3 ,:]
65
- @views @inbounds u[2 ,:] .= u[end - 2 ,:]
66
- @views @inbounds u[end - 1 ,:] .= u[3 ,:]
67
- @views @inbounds u[end ,:] .= u[4 ,:]
63
+ # periodic bc - mimic MPI communication with (reduced precision) type Tcomm
64
+ @views @inbounds u[1 ,:] .= T .( Tcomm .( u[end - 3 ,:]))
65
+ @views @inbounds u[2 ,:] .= T .( Tcomm .( u[end - 2 ,:]))
66
+ @views @inbounds u[end - 1 ,:] .= T .( Tcomm .( u[3 ,:]))
67
+ @views @inbounds u[end ,:] .= T .( Tcomm .( u[4 ,:]))
68
68
69
69
# tangential bc
70
70
@views @inbounds u[:,1 ] .= one_minus_α* u[:,4 ]
71
71
@views @inbounds u[:,2 ] .= one_minus_α* u[:,3 ]
72
72
@views @inbounds u[:,end - 1 ] .= one_minus_α* u[:,end - 2 ]
73
73
@views @inbounds u[:,end ] .= one_minus_α* u[:,end - 3 ]
74
74
75
- # # periodic bc
76
- # @views copyto!(u[1,:],u[end-3,:])
77
- # @views copyto!(u[2,:],u[end-2,:])
78
- # @views copyto!(u[end-1,:],u[3,:])
79
- # @views copyto!(u[end,:],u[4,:])
80
- #
81
- # # tangential bc
82
- # @views copyto!(u[:,1],one_minus_α.*u[:,4])
83
- # @views copyto!(u[:,2],one_minus_α.*u[:,3])
84
- # @views copyto!(u[:,end-1],one_minus_α.*u[:,end-2])
85
- # @views copyto!(u[:,end],one_minus_α.*u[:,end-3])
86
75
end
87
76
88
77
""" Copy ghost points for v from inside to the halo in the nonperiodic case. """
@@ -98,13 +87,13 @@ function ghost_points_v_nonperiodic!(C::Constants,v::AbstractMatrix)
98
87
end
99
88
100
89
""" Copy ghost points for v from inside to the halo in the periodic case. """
101
- function ghost_points_v_periodic! (v:: AbstractMatrix )
90
+ function ghost_points_v_periodic! (:: Type{Tcomm} , v:: Array{T,2} ) where {Tcomm,T}
102
91
103
- # tangential boundary condition
104
- @views @inbounds v[1 ,:] .= v[end - 3 ,:]
105
- @views @inbounds v[2 ,:] .= v[end - 2 ,:]
106
- @views @inbounds v[end - 1 ,:] .= v[3 ,:]
107
- @views @inbounds v[end ,:] .= v[4 ,:]
92
+ # tangential boundary condition - mimic MPI communication with (reduced precision) type Tcomm
93
+ @views @inbounds v[1 ,:] .= T .( Tcomm .( v[end - 3 ,:]))
94
+ @views @inbounds v[2 ,:] .= T .( Tcomm .( v[end - 2 ,:]))
95
+ @views @inbounds v[end - 1 ,:] .= T .( Tcomm .( v[3 ,:]))
96
+ @views @inbounds v[end ,:] .= T .( Tcomm .( v[4 ,:]))
108
97
end
109
98
110
99
""" Copy ghost points for η from inside to the halo in the nonperiodic case. """
@@ -120,14 +109,15 @@ function ghost_points_η_nonperiodic!(η::AbstractMatrix)
120
109
end
121
110
122
111
""" Copy ghost points for η from inside to the halo in the periodic case. """
123
- function ghost_points_η_periodic! (η:: AbstractMatrix )
112
+ function ghost_points_η_periodic! (:: Type{Tcomm} , η:: Array{T,2} ) where {Tcomm,T}
124
113
125
114
# corner points are copied twice, but it's faster!
126
- @views @inbounds η[1 ,:] .= η[end - 1 ,:]
127
- @views @inbounds η[end ,:] .= η[2 ,:]
115
+ # mimic MPI communication with (reduced precision) type Tcomm
116
+ @views @inbounds η[1 ,:] .= T .(Tcomm .(η[end - 1 ,:]))
117
+ @views @inbounds η[end ,:] .= T .(Tcomm .(η[2 ,:]))
128
118
129
- @views @inbounds η[:,1 ] .= η[:,2 ]
130
- @views @inbounds η[:,end ] .= η[:,end - 1 ]
119
+ @views @inbounds η[:,1 ] .= T .( Tcomm .( η[:,2 ]))
120
+ @views @inbounds η[:,end ] .= T .( Tcomm .( η[:,end - 1 ]))
131
121
end
132
122
133
123
""" Copy ghost points for η from inside to the halo in the nonperiodic case. """
@@ -149,14 +139,14 @@ function ghost_points_sst_nonperiodic!(G::Grid,sst::AbstractMatrix)
149
139
end
150
140
151
141
""" Copy ghost points for η from inside to the halo in the periodic case. """
152
- function ghost_points_sst_periodic! (G :: Grid ,sst:: AbstractMatrix )
142
+ function ghost_points_sst_periodic! (:: Type{Tcomm} ,sst:: Array{T,2} ,G :: Grid ) where {Tcomm,T}
153
143
154
144
@unpack halosstx,halossty = G
155
145
156
146
# corner points are copied twice, but it's faster!
157
147
for i ∈ 1 : halosstx
158
- @views @inbounds sst[i,:] .= sst[end - 2 * halosstx+ i,:]
159
- @views @inbounds sst[end - halosstx+ i,:] .= sst[halosstx+ i,:]
148
+ @views @inbounds sst[i,:] .= T .( Tcomm .( sst[end - 2 * halosstx+ i,:]))
149
+ @views @inbounds sst[end - halosstx+ i,:] .= T .( Tcomm .( sst[halosstx+ i,:]))
160
150
end
161
151
162
152
for j ∈ 1 : halossty
@@ -175,9 +165,10 @@ function ghost_points!( u::AbstractMatrix,
175
165
C = S. constants
176
166
177
167
if bc == " periodic"
178
- ghost_points_u_periodic! (C,u)
179
- ghost_points_v_periodic! (v)
180
- ghost_points_η_periodic! (η)
168
+ @unpack Tcomm = S. parameters
169
+ ghost_points_u_periodic! (Tcomm,u,C)
170
+ ghost_points_v_periodic! (Tcomm,v)
171
+ ghost_points_η_periodic! (Tcomm,η)
181
172
else
182
173
ghost_points_u_nonperiodic! (C,u)
183
174
ghost_points_v_nonperiodic! (C,v)
@@ -192,7 +183,8 @@ function ghost_points_sst!(sst::AbstractMatrix,S::ModelSetup)
192
183
G = S. grid
193
184
194
185
if bc == " periodic"
195
- ghost_points_sst_periodic! (G,sst)
186
+ @unpack Tcomm = S. parameters
187
+ ghost_points_sst_periodic! (Tcomm,sst,G)
196
188
else
197
189
ghost_points_sst_nonperiodic! (G,sst)
198
190
end
0 commit comments