Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D MPI example & docs #102

Merged
merged 8 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix few MPI bugs
  • Loading branch information
albert-de-montserrat committed May 9, 2024
commit 9b1328b17ad5c9b99bfc82b9e4a3bb060ae49369
3 changes: 3 additions & 0 deletions src/JustPIC.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module JustPIC

# using ImplicitGlobalGrid
using MPI: MPI

abstract type AbstractBackend end
struct CPUBackend <: AbstractBackend end
struct AMDGPUBackend <: AbstractBackend end
Expand Down
8 changes: 4 additions & 4 deletions src/JustPIC_CPU.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module _2D
using ImplicitGlobalGrid
using MPI: MPI
# using MPI: MPI
using MuladdMacro
using ParallelStencil
using CellArrays
using Atomix
using ..JustPIC

import ..JustPIC: AbstractBackend, CPUBackend, CUDABackend, AMDGPUBackend
import ..JustPIC: AbstractBackend, CPUBackend

@init_parallel_stencil(Threads, Float64, 2)

Expand All @@ -28,14 +28,14 @@ end

module _3D
using ImplicitGlobalGrid
using MPI: MPI
# using MPI: MPI
using MuladdMacro
using ParallelStencil
using CellArrays
using Atomix
using ..JustPIC

import ..JustPIC: AbstractBackend, CPUBackend, CUDABackend, AMDGPUBackend
import ..JustPIC: AbstractBackend, CPUBackend

@init_parallel_stencil(Threads, Float64, 3)

Expand Down
9 changes: 5 additions & 4 deletions src/Utils.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
function add_global_ghost_nodes(x::AbstractArray, dx, origin)
function add_global_ghost_nodes(x::AbstractArray, dx, origin; backend = CPUBackend)
x1, x2 = extrema(x)
xI = round(x1 - dx; sigdigits=5)
xF = round(x2 + dx; sigdigits=5)
x1 == origin[1] && (x = vcat(xI, x))
x2 == origin[2] && (x = vcat(x, xF))
return x = TA(x)
return x = TA(backend)(x)
end

function add_ghost_nodes(x::AbstractArray, dx, origin)
function add_ghost_nodes(x::AbstractArray, dx, origin; backend = CPUBackend)
x1, x2 = extrema(x)
xI = round(x1 - dx; sigdigits=5)
xF = round(x2 + dx; sigdigits=5)
return x = TA(vcat(xI, Array(x), xF))
# LinRange(xI, xF, length(x)+2)
return x = TA(backend)(vcat(xI, Array(x), xF))
end

"""
Expand Down
6 changes: 3 additions & 3 deletions src/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ unwrap_abstractarray(x::AbstractArray) = typeof(x).name.wrapper

# @inline cell_index(xᵢ::T, dxᵢ::T) where {T} = abs(Int(xᵢ ÷ dxᵢ)) + 1
@inline cell_index(xᵢ::T, dxᵢ::T) where {T} = abs(Int(trunc(xᵢ / dxᵢ))) + 1
@inline cell_index(xᵢ::T, xvᵢ::AbstractRange{T}) where {T} =
@inline cell_index(xᵢ::T, xvᵢ::AbstractVector{T}) where {T} =
cell_index(xᵢ, xvᵢ, abs(xvᵢ[2] - xvᵢ[1]))

# generic one that works for any grid
@inline function cell_index(xᵢ::T, xvᵢ::AbstractRange{T}, dxᵢ::T) where {T}
@inline function cell_index(xᵢ::T, xvᵢ::AbstractVector{T}, dxᵢ::T) where {T}
xv₀ = first(xvᵢ)
if iszero(xv₀)
return cell_index(xᵢ, dxᵢ)
Expand All @@ -91,7 +91,7 @@ unwrap_abstractarray(x::AbstractArray) = typeof(x).name.wrapper
end
end

@inline function cell_index(x::NTuple{N,T}, xv::NTuple{N,AbstractRange{T}}) where {N,T}
@inline function cell_index(x::NTuple{N,T}, xv::NTuple{N,AbstractVector{T}}) where {N,T}
ntuple(Val(N)) do i
Base.@_inline_meta
cell_index(x[i], xv[i])
Expand Down