From 25ad9f256f6791a0bc3977c1c026aa14bdb91f78 Mon Sep 17 00:00:00 2001 From: Michael Hardman <29800382+mrhardman@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:59:59 +0000 Subject: [PATCH] Bugfix of MPI communication of the delta_phi increments to the distributed 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. --- moment_kinetics/src/em_fields.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/moment_kinetics/src/em_fields.jl b/moment_kinetics/src/em_fields.jl index 978af1863..5d757a511 100644 --- a/moment_kinetics/src/em_fields.jl +++ b/moment_kinetics/src/em_fields.jl @@ -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 @@ -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