Skip to content

Commit

Permalink
same for P4estMesh and T8codeMesh
Browse files Browse the repository at this point in the history
  • Loading branch information
benegee committed Sep 10, 2024
1 parent a7d300c commit 653abff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/callbacks_step/analysis_dg2d_parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ function integrate_via_indices(func::Func, u,
if local_integral isa Real
global_integral = MPI.Reduce!(Ref(local_integral), +, mpi_root(), mpi_comm())
else
global_integral = MPI.Reduce!(Base.unsafe_convert(Ptr{Float64}, Ref(local_integral)), +, mpi_root(), mpi_comm())
global_integral = MPI.Reduce!(Base.unsafe_convert(Ptr{Float64},
Ref(local_integral)), +,
mpi_root(), mpi_comm())
end

if mpi_isroot()
Expand Down Expand Up @@ -205,10 +207,20 @@ function integrate_via_indices(func::Func, u,
end
end

global_integral = MPI.Reduce!(Ref(integral), +, mpi_root(), mpi_comm())
if integral isa Real
global_integral = MPI.Reduce!(Ref(integral), +, mpi_root(), mpi_comm())
else
global_integral = MPI.Reduce!(Base.unsafe_convert(Ptr{Float64}, Ref(integral)),
+, mpi_root(), mpi_comm())
end
total_volume = MPI.Reduce(volume, +, mpi_root(), mpi_comm())
if mpi_isroot()
integral = convert(typeof(integral), global_integral[])
if integral isa Real
integral = global_integral[]
else
global_wrapped = unsafe_wrap(Array, global_integral, length(integral))
integral = convert(typeof(integral), global_wrapped)
end
else
integral = convert(typeof(integral), NaN * integral)
total_volume = volume # non-root processes receive nothing from reduce -> overwrite
Expand Down
14 changes: 12 additions & 2 deletions src/callbacks_step/analysis_dg3d_parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,20 @@ function integrate_via_indices(func::Func, u,
end
end

global_integral = MPI.Reduce!(Ref(integral), +, mpi_root(), mpi_comm())
if integral isa Real
global_integral = MPI.Reduce!(Ref(integral), +, mpi_root(), mpi_comm())
else
global_integral = MPI.Reduce!(Base.unsafe_convert(Ptr{Float64}, Ref(integral)),
+, mpi_root(), mpi_comm())
end
total_volume = MPI.Reduce(volume, +, mpi_root(), mpi_comm())
if mpi_isroot()
integral = convert(typeof(integral), global_integral[])
if integral isa Real
integral = global_integral[]
else
global_wrapped = unsafe_wrap(Array, global_integral, length(integral))
integral = convert(typeof(integral), global_wrapped)
end
else
integral = convert(typeof(integral), NaN * integral)
total_volume = volume # non-root processes receive nothing from reduce -> overwrite
Expand Down

0 comments on commit 653abff

Please sign in to comment.