@@ -207,26 +207,18 @@ function calc_max_scaled_speed(backend::Backend, u, mesh, constant_speed, equati
207207 @unpack contravariant_vectors, inverse_jacobian = cache. elements
208208
209209 num_elements = nelements (dg, cache)
210- max_scaled_speeds = allocate (backend , eltype (u), num_elements )
211-
212- kernel! = max_scaled_speed_KAkernel! (backend)
213- kernel! (max_scaled_speeds, u, typeof (mesh), constant_speed, equations, dg,
214- contravariant_vectors ,
215- inverse_jacobian;
216- ndrange = num_elements)
217-
218- return maximum (max_scaled_speeds )
219- end
210+ init = neutral = AcceleratedKernels . neutral_element (Base . max , eltype (u))
211+
212+ # Provide a custom neutral and init element since we "reduce" over 1:num_elements
213+ max_scaled_speed = AcceleratedKernels . mapreduce (Base . max, 1 : num_elements, backend; init, neutral) do element
214+ max_scaled_speed_per_element (u, mesh, constant_speed ,
215+ equations, dg,
216+ contravariant_vectors,
217+ inverse_jacobian,
218+ element )
219+ end
220220
221- @kernel function max_scaled_speed_KAkernel! (max_scaled_speeds, u, MeshT, constant_speed,
222- equations,
223- dg, contravariant_vectors, inverse_jacobian)
224- element = @index (Global)
225- max_scaled_speeds[element] = max_scaled_speed_per_element (u, MeshT, constant_speed,
226- equations, dg,
227- contravariant_vectors,
228- inverse_jacobian,
229- element)
221+ return max_scaled_speed
230222end
231223
232224include (" stepsize_dg1d.jl" )
0 commit comments