Skip to content

Commit

Permalink
Include @views to actually reduce allocations
Browse files Browse the repository at this point in the history
Not sure why these lines cannot get to zero allocations, might be a
'bug' in the Julia compiler...
  • Loading branch information
johnomotani committed Jan 14, 2025
1 parent a0b0a72 commit 7a6fff1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion moment_kinetics/src/electron_vpa_advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function update_electron_speed_vpa!(advect, density, upar, ppar, moments, vpa,
ppar[iz] +
0.5 * source_density_amplitude[iz] / density[iz]
@loop_vperp ivperp begin
@. speed[:,ivperp,iz] += term1 + vpa * term2_over_vpa
@views @. speed[:,ivperp,iz] += term1 + vpa * term2_over_vpa
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions moment_kinetics/src/external_sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -993,17 +993,17 @@ Note that this function operates on a single point in `r`, given by `ir`, and `p
# Factor of 1/sqrt(π) (for 1V) or 1/π^(3/2) (for 2V/3V) is absorbed by the
# normalisation of F
vperp_unnorm = vperp_grid[ivperp] * this_vth
@. pdf_out[:,ivperp,iz] +=
@views @. pdf_out[:,ivperp,iz] +=
this_prefactor *
exp(-(vperp_unnorm^2 + (vpa_grid * this_vth + this_upar)^2) * me_over_mi / source_T)
end
end

if electron_source.source_type == "energy"
# Take particles out of pdf so source does not change density
@loop_z_vperp_vpa iz ivperp ivpa begin
pdf_out[ivpa,ivperp,iz] -= dt * source_amplitude[iz] *
pdf_in[ivpa,ivperp,iz]
@loop_z_vperp iz ivperp begin
@views @. pdf_out[:,ivperp,iz] -= dt * source_amplitude[iz] *
pdf_in[:,ivperp,iz]
end
end

Expand Down

0 comments on commit 7a6fff1

Please sign in to comment.