Skip to content

Commit

Permalink
Bugfix of MPI communication of the delta_phi increments to the distri…
Browse files Browse the repository at this point in the history
…buted calculation of the potential. The script test_scripts/phi_from_Epar_test.jl has been run to confirm that the code is working for a mix of r and z resolutions on 2, 4, and 8 cores.
  • Loading branch information
mrhardman committed Jan 3, 2025
1 parent 48a6e59 commit 25ad9f2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions moment_kinetics/src/em_fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module em_fields

export setup_em_fields
export update_phi!
# for testing
export calculate_phi_from_Epar!

using ..type_definitions: mk_float
using ..array_allocation: allocate_shared_float
Expand Down Expand Up @@ -210,10 +212,13 @@ function calculate_phi_from_Epar!(phi, Epar, r, z, z_spectral)
# Add contributions to integral along z from processes at smaller z-values than
# this one.
this_delta_phi = r.scratch2
@loop_r ir begin
this_delta_phi[ir] = phi[end,ir] - phi[1,ir]
end
for irank 0:z.nrank-2
# update this_delta_phi before broadcasting
@loop_r ir begin
this_delta_phi[ir] = phi[end,ir] - phi[1,ir]
end
# broadcast this_delta_phi from z.irank = irank to all processes
# updating this_delta_phi everywhere
MPI.Bcast!(this_delta_phi, z.comm; root=irank)
if z.irank > irank
@loop_r_z ir iz begin
Expand Down

0 comments on commit 25ad9f2

Please sign in to comment.