Skip to content

Commit 37ded8b

Browse files
authored
replace Threads.nthreads by Threads.maxthreadid (#2612)
* replace Threads.nthreads by Threads.maxthreadid * format
1 parent deb3f55 commit 37ded8b

File tree

19 files changed

+117
-113
lines changed

19 files changed

+117
-113
lines changed

examples/tree_2d_dgsem/elixir_euler_vortex_amr.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function IndicatorVortex(semi)
1515
alpha = Vector{real(basis)}()
1616
A = Array{real(basis), 2}
1717
indicator_threaded = [A(undef, nnodes(basis), nnodes(basis))
18-
for _ in 1:Threads.nthreads()]
18+
for _ in 1:Threads.maxthreadid()]
1919
cache = (; semi.mesh, alpha, indicator_threaded)
2020

2121
return IndicatorVortex{typeof(cache)}(cache)
@@ -119,7 +119,7 @@ initial_condition = initial_condition_isentropic_vortex
119119
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
120120
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
121121
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
122-
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
122+
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
123123
# `StepsizeCallback` (CFL-Condition) and less diffusion.
124124
solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive))
125125

@@ -153,7 +153,7 @@ alive_callback = AliveCallback(analysis_interval = analysis_interval)
153153
# Add `:temperature` to `extra_node_variables` tuple ...
154154
extra_node_variables = (:temperature,)
155155

156-
# ... and specify the function `get_node_variable` for this symbol,
156+
# ... and specify the function `get_node_variable` for this symbol,
157157
# with first argument matching the symbol (turned into a type via `Val`) for dispatching.
158158
function Trixi.get_node_variable(::Val{:temperature}, u, mesh, equations, dg, cache)
159159
n_nodes = nnodes(dg)

src/solvers/dgmulti/dg.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function create_cache(mesh::DGMultiMesh{NDIMS}, equations, dg::DGMultiWeakForm,
189189

190190
# local storage for volume integral and source computations
191191
local_values_threaded = [allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
192-
for _ in 1:Threads.nthreads()]
192+
for _ in 1:Threads.maxthreadid()]
193193

194194
# For curved meshes, we interpolate geometric terms from nodal points to quadrature points.
195195
# For affine meshes, we just access one element of this interpolated data.
@@ -200,9 +200,9 @@ function create_cache(mesh::DGMultiMesh{NDIMS}, equations, dg::DGMultiWeakForm,
200200

201201
# for scaling by curved geometric terms (not used by affine DGMultiMesh)
202202
flux_threaded = [[allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
203-
for _ in 1:NDIMS] for _ in 1:Threads.nthreads()]
203+
for _ in 1:NDIMS] for _ in 1:Threads.maxthreadid()]
204204
rotated_flux_threaded = [allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
205-
for _ in 1:Threads.nthreads()]
205+
for _ in 1:Threads.maxthreadid()]
206206

207207
return (; md, weak_differentiation_matrices, lift_scalings, invJ, dxidxhatj,
208208
u_values, u_face_values, flux_face_values,

src/solvers/dgmulti/dg_parabolic.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ function create_cache_parabolic(mesh::DGMultiMesh,
3838
gradients_face_values = ntuple(_ -> similar(u_face_values), ndims(mesh))
3939

4040
local_u_values_threaded = [similar(u_transformed, dg.basis.Nq)
41-
for _ in 1:Threads.nthreads()]
41+
for _ in 1:Threads.maxthreadid()]
4242
local_flux_viscous_threaded = [SVector{ndims(mesh)}(ntuple(_ -> similar(u_transformed,
4343
dg.basis.Nq),
4444
ndims(mesh)))
45-
for _ in 1:Threads.nthreads()]
45+
for _ in 1:Threads.maxthreadid()]
4646
local_flux_face_values_threaded = [similar(scalar_flux_face_values[:, 1])
47-
for _ in 1:Threads.nthreads()]
47+
for _ in 1:Threads.maxthreadid()]
4848

4949
return (; u_transformed, gradients, flux_viscous,
5050
weak_differentiation_matrices, strong_differentiation_matrices,
@@ -152,9 +152,9 @@ function calc_gradient_interface_flux!(scalar_flux_face_values,
152152
idM, idP = mapM[face_node_index], mapP[face_node_index]
153153
uM = u_face_values[idM]
154154
uP = u_face_values[idP]
155-
# Here, we use the "strong" formulation to compute the gradient.
156-
# This guarantees that the parabolic formulation is symmetric and
157-
# stable on curved meshes with variable geometric terms.
155+
# Here, we use the "strong" formulation to compute the gradient.
156+
# This guarantees that the parabolic formulation is symmetric and
157+
# stable on curved meshes with variable geometric terms.
158158
scalar_flux_face_values[idM] = 0.5f0 * (uP - uM)
159159
end
160160

src/solvers/dgmulti/flux_differencing.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ function create_cache(mesh::DGMultiMesh, equations, dg::DGMultiFluxDiffSBP, Real
311311
lift_scalings = rd.wf ./ rd.wq[rd.Fmask] # lift scalings for diag-norm SBP operators
312312

313313
local_values_threaded = [allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
314-
for _ in 1:Threads.nthreads()]
314+
for _ in 1:Threads.maxthreadid()]
315315

316316
# Use an array of SVectors (chunks of `nvars` are contiguous in memory) to speed up flux differencing
317317
fluxdiff_local_threaded = [zeros(SVector{nvars, uEltype}, rd.Nq)
318-
for _ in 1:Threads.nthreads()]
318+
for _ in 1:Threads.maxthreadid()]
319319

320320
return (; md, Qrst_skew, dxidxhatj = md.rstxyzJ,
321321
invJ = inv.(md.J), lift_scalings, inv_wq = inv.(rd.wq),
@@ -356,16 +356,16 @@ function create_cache(mesh::DGMultiMesh, equations, dg::DGMultiFluxDiff, RealT,
356356

357357
# local storage for interface fluxes, rhs, and source
358358
local_values_threaded = [allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
359-
for _ in 1:Threads.nthreads()]
359+
for _ in 1:Threads.maxthreadid()]
360360

361361
# Use an array of SVectors (chunks of `nvars` are contiguous in memory) to speed up flux differencing
362362
# The result is then transferred to rhs_local_threaded::StructArray{<:SVector} before
363363
# projecting it and storing it into `du`.
364364
fluxdiff_local_threaded = [zeros(SVector{nvars, uEltype}, num_quad_points_total)
365-
for _ in 1:Threads.nthreads()]
365+
for _ in 1:Threads.maxthreadid()]
366366
rhs_local_threaded = [allocate_nested_array(uEltype, nvars,
367367
(num_quad_points_total,), dg)
368-
for _ in 1:Threads.nthreads()]
368+
for _ in 1:Threads.maxthreadid()]
369369

370370
# interpolate geometric terms to both quadrature and face values for curved meshes
371371
(; Vq, Vf) = dg.basis

src/solvers/dgmulti/flux_differencing_gauss_sbp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ function create_cache(mesh::DGMultiMesh, equations,
427427

428428
nvars = nvariables(equations)
429429
rhs_volume_local_threaded = [allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
430-
for _ in 1:Threads.nthreads()]
430+
for _ in 1:Threads.maxthreadid()]
431431
gauss_volume_local_threaded = [allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
432-
for _ in 1:Threads.nthreads()]
432+
for _ in 1:Threads.maxthreadid()]
433433

434434
return (; cache..., projection_matrix_gauss_to_face, gauss_LIFT, inv_gauss_weights,
435435
rhs_volume_local_threaded, gauss_volume_local_threaded,

src/solvers/dgmulti/shock_capturing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function create_cache(::Type{IndicatorHennemannGassner}, equations::AbstractEqua
3939
alpha_tmp = similar(alpha)
4040

4141
A = Vector{real(basis)}
42-
indicator_threaded = [A(undef, nnodes(basis)) for _ in 1:Threads.nthreads()]
43-
modal_threaded = [A(undef, nnodes(basis)) for _ in 1:Threads.nthreads()]
42+
indicator_threaded = [A(undef, nnodes(basis)) for _ in 1:Threads.maxthreadid()]
43+
modal_threaded = [A(undef, nnodes(basis)) for _ in 1:Threads.maxthreadid()]
4444

4545
# initialize inverse Vandermonde matrices at Gauss-Legendre nodes
4646
(; N) = basis

src/solvers/dgmulti/types.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ Base.real(rd::RefElemData) = eltype(rd.r)
7272
7373
Create a discontinuous Galerkin method which uses
7474
- Approximations of polynomial degree `polydeg`.
75-
- Element type `element_type` (`Tri()`, `Quad()`, `Tet()`, `Hex()`, and `Wedge()` are
75+
- Element type `element_type` (`Tri()`, `Quad()`, `Tet()`, `Hex()`, and `Wedge()` are
7676
currently supported)
7777
7878
Optional:
79-
- `approximation_type` (default is `Polynomial()`; `SBP()` also supported for `Tri()`,
79+
- `approximation_type` (default is `Polynomial()`; `SBP()` also supported for `Tri()`,
8080
`Quad()`, and `Hex()` element types).
81-
- `RefElemData_kwargs` are additional keyword arguments for `RefElemData`, such as
81+
- `RefElemData_kwargs` are additional keyword arguments for `RefElemData`, such as
8282
`quad_rule_vol`.
83-
83+
8484
For more info, see the [StartUpDG.jl docs](https://jlchan.github.io/StartUpDG.jl/dev/).
8585
8686
!!! note "Wedge elements"
87-
For `Wedge` elements (i.e. triangular prisms), the polynomial degree may optionally be
87+
For `Wedge` elements (i.e. triangular prisms), the polynomial degree may optionally be
8888
specified as a tuple of the form `polydeg = (polydeg_tri, polydeg_line)`.
8989
"""
9090
function DGMulti(; polydeg = nothing,
@@ -100,9 +100,9 @@ function DGMulti(; polydeg = nothing,
100100
polydeg = polydeg, kwargs...)
101101
end
102102

103-
# `Wedge` element types can optionally take `polydeg = (polydeg_tri, polydeg_line)`, which
103+
# `Wedge` element types can optionally take `polydeg = (polydeg_tri, polydeg_line)`, which
104104
# constructs a `TensorProductWedge` approximation. Since Julia does not dispatch on keyword
105-
# arguments, we wrap a method which makes `polydeg` a positional argument.
105+
# arguments, we wrap a method which makes `polydeg` a positional argument.
106106
function DGMulti(element_type::Wedge,
107107
approximation_type,
108108
volume_integral,
@@ -376,7 +376,7 @@ end
376376
function SimpleKronecker(NDIMS, A, eltype_A = eltype(A))
377377
@assert size(A, 1) == size(A, 2) # check if square
378378
tmp_storage = [zeros(eltype_A, ntuple(_ -> size(A, 2), NDIMS)...)
379-
for _ in 1:Threads.nthreads()]
379+
for _ in 1:Threads.maxthreadid()]
380380
return SimpleKronecker{NDIMS, typeof(A), typeof(tmp_storage)}(A, tmp_storage)
381381
end
382382

src/solvers/dgsem_p4est/dg_2d.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ function create_cache(mesh::Union{P4estMesh{2}, P4estMeshView{2}, T8codeMesh{2}}
1414
MA2d = MArray{Tuple{nvariables(equations), nnodes(mortar_l2)},
1515
uEltype, 2,
1616
nvariables(equations) * nnodes(mortar_l2)}
17-
fstar_primary_upper_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
18-
fstar_primary_lower_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
19-
fstar_secondary_upper_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
20-
fstar_secondary_lower_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
21-
u_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
17+
fstar_primary_upper_threaded = MA2d[MA2d(undef) for _ in 1:Threads.maxthreadid()]
18+
fstar_primary_lower_threaded = MA2d[MA2d(undef) for _ in 1:Threads.maxthreadid()]
19+
fstar_secondary_upper_threaded = MA2d[MA2d(undef) for _ in 1:Threads.maxthreadid()]
20+
fstar_secondary_lower_threaded = MA2d[MA2d(undef) for _ in 1:Threads.maxthreadid()]
21+
u_threaded = MA2d[MA2d(undef) for _ in 1:Threads.maxthreadid()]
2222

2323
cache = (; fstar_primary_upper_threaded, fstar_primary_lower_threaded,
2424
fstar_secondary_upper_threaded, fstar_secondary_lower_threaded,

src/solvers/dgsem_p4est/dg_3d.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ function create_cache(mesh::Union{P4estMesh{3}, T8codeMesh{3}}, equations,
1313
fstar_primary_threaded = [Array{uEltype, 4}(undef, nvariables(equations),
1414
nnodes(mortar_l2),
1515
nnodes(mortar_l2), 4)
16-
for _ in 1:Threads.nthreads()] |> VecOfArrays
16+
for _ in 1:Threads.maxthreadid()] |> VecOfArrays
1717
fstar_secondary_threaded = [Array{uEltype, 4}(undef, nvariables(equations),
1818
nnodes(mortar_l2),
1919
nnodes(mortar_l2), 4)
20-
for _ in 1:Threads.nthreads()] |> VecOfArrays
20+
for _ in 1:Threads.maxthreadid()] |> VecOfArrays
2121

2222
fstar_tmp_threaded = [Array{uEltype, 3}(undef, nvariables(equations),
2323
nnodes(mortar_l2), nnodes(mortar_l2))
24-
for _ in 1:Threads.nthreads()] |> VecOfArrays
24+
for _ in 1:Threads.maxthreadid()] |> VecOfArrays
2525
u_threaded = [Array{uEltype, 3}(undef, nvariables(equations), nnodes(mortar_l2),
2626
nnodes(mortar_l2))
27-
for _ in 1:Threads.nthreads()] |> VecOfArrays
27+
for _ in 1:Threads.maxthreadid()] |> VecOfArrays
2828

2929
(; fstar_primary_threaded, fstar_secondary_threaded, fstar_tmp_threaded, u_threaded)
3030
end

src/solvers/dgsem_tree/dg_1d.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ function create_cache(mesh::Union{TreeMesh{1}, StructuredMesh{1}}, equations,
4242

4343
A2dp1_x = Array{uEltype, 2}
4444
fstar1_L_threaded = A2dp1_x[A2dp1_x(undef, nvariables(equations), nnodes(dg) + 1)
45-
for _ in 1:Threads.nthreads()]
45+
for _ in 1:Threads.maxthreadid()]
4646
fstar1_R_threaded = A2dp1_x[A2dp1_x(undef, nvariables(equations), nnodes(dg) + 1)
47-
for _ in 1:Threads.nthreads()]
47+
for _ in 1:Threads.maxthreadid()]
4848

4949
return (; cache..., fstar1_L_threaded, fstar1_R_threaded)
5050
end
@@ -54,9 +54,9 @@ function create_cache(mesh::Union{TreeMesh{1}, StructuredMesh{1}}, equations,
5454
dg::DG, uEltype)
5555
A2dp1_x = Array{uEltype, 2}
5656
fstar1_L_threaded = A2dp1_x[A2dp1_x(undef, nvariables(equations), nnodes(dg) + 1)
57-
for _ in 1:Threads.nthreads()]
57+
for _ in 1:Threads.maxthreadid()]
5858
fstar1_R_threaded = A2dp1_x[A2dp1_x(undef, nvariables(equations), nnodes(dg) + 1)
59-
for _ in 1:Threads.nthreads()]
59+
for _ in 1:Threads.maxthreadid()]
6060

6161
return (; fstar1_L_threaded, fstar1_R_threaded)
6262
end
@@ -347,7 +347,7 @@ end
347347
fstar1_R[:, nnodes(dg) + 1] .= zero(eltype(fstar1_R))
348348

349349
for i in 2:nnodes(dg) # We compute FV02 fluxes at the (nnodes(dg) - 1) subcell boundaries
350-
# Reference element:
350+
# Reference element:
351351
# -1 ------------------0------------------ 1 -> x
352352
# Gauss-Lobatto-Legendre nodes (schematic for k = 3):
353353
# . . . .
@@ -367,9 +367,9 @@ end
367367
# piecewise linear solution in both subcells next to the subcell interface.
368368
# Since these subcell boundaries are not aligned with the DG nodes,
369369
# on each neighboring subcell two linear solutions are reconstructed => 4 point stencil.
370-
# For the outer interfaces the stencil shrinks since we do not consider values
370+
# For the outer interfaces the stencil shrinks since we do not consider values
371371
# outside the element (this is a volume integral).
372-
#
372+
#
373373
# The left subcell node values are labelled `_ll` (left-left) and `_lr` (left-right), while
374374
# the right subcell node values are labelled `_rl` (right-left) and `_rr` (right-right).
375375

0 commit comments

Comments
 (0)