Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 896368b

Browse files
bors[bot]mwarusz
andauthored
Merge #1537
1537: Use static range in Grad setproperty! r=mwarusz a=mwarusz # Description After #1458 I noticed a slowdown. This PR proposes a fix. Running ```julia --project=. experiments/AtmosLES/bomex_les.jl --monitor-timestep-duration 100steps``` I get Before: ``` ┌ Info: Wall-clock time per time-step (statistics across MPI ranks) │ maximum (s) = 1.5273617989999998e-02 │ minimum (s) = 1.5273617989999998e-02 │ median (s) = 1.5273617989999998e-02 └ std (s) = NaN ``` After: ``` Info: Wall-clock time per time-step (statistics across MPI ranks) │ maximum (s) = 1.1554147779999999e-02 │ minimum (s) = 1.1554147779999999e-02 │ median (s) = 1.1554147779999999e-02 └ std (s) = NaN ``` The fix relies on unexported `StaticArrays` API but JuliaArrays/StaticArrays.jl#474 makes me think that this is ok. Co-authored-by: Maciej Waruszewski <[email protected]>
2 parents 2f3ed54 + 9996457 commit 896368b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Utilities/VariableTemplates/VariableTemplates.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ end
309309
offset += 1
310310
elseif T <: StaticArray
311311
N = length(T)
312-
retexpr = :(array[:, ($(offset + 1)):($(offset + N))] = val)
312+
retexpr = :(
313+
array[
314+
:,
315+
# static range is used here to force dispatch to
316+
# StaticArrays setindex! because generic setindex! is slow
317+
StaticArrays.SUnitRange($(offset + 1), $(offset + N)),
318+
] = val
319+
)
313320
offset += N
314321
else
315322
offset += varsize(T)

0 commit comments

Comments
 (0)