Skip to content

Commit

Permalink
Merge pull request #46 from gridap/petsc_ksp_partitioned_simulations_…
Browse files Browse the repository at this point in the history
…mpi_mode_support

PetscLinearSolver partitioned mpi support
  • Loading branch information
fverdugo authored Nov 5, 2021
2 parents c20548c + 725c842 commit 3ba0de4
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/PETScLinearSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ function Algebra.solve!(x::AbstractVector,ns::PETScLinearSolverNS,b::AbstractVec
x
end

function Algebra.solve!(x::PVector,ns::PETScLinearSolverNS,b::PVector)
X = similar(b,eltype(b),(axes(b)[1],))
copy!(X,x)
Y = convert(PETScVector,X)
solve!(Y,ns,b)
_copy_and_exchange!(x,Y)
end



function Algebra.numerical_setup!(ns::PETScLinearSolverNS,A::AbstractMatrix)
ns.A = convert(PETScMatrix,A)
@check_error_code PETSC.KSPSetOperators(ns.ksp[],ns.A.mat[],ns.A.mat[])
Expand Down
9 changes: 4 additions & 5 deletions test/PLaplacianTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ using Test

function main(parts)
options = "-snes_type newtonls -snes_linesearch_type basic -snes_linesearch_damping 1.0 -snes_rtol 1.0e-14 -snes_atol 0.0 -snes_monitor -pc_type jacobi -ksp_type gmres -ksp_monitor -snes_converged_reason"
GridapPETSc.Init(args=split(options))

main(parts,FullyAssembledRows())
main(parts,SubAssembledRows())

GridapPETSc.Finalize()
GridapPETSc.with(args=split(options)) do
main(parts,FullyAssembledRows())
main(parts,SubAssembledRows())
end
end

function main(parts,strategy)
Expand Down
46 changes: 46 additions & 0 deletions test/PoissonTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Gridap
using Gridap.Algebra
using Gridap.FESpaces
using GridapDistributed
using GridapPETSc
using PartitionedArrays
using Test

function main(parts)
options = "-info -pc_type jacobi -ksp_type cg -ksp_monitor -ksp_rtol 1.0e-12"
GridapPETSc.with(args=split(options)) do
domain = (0,4,0,4)
cells = (4,4)
model = CartesianDiscreteModel(parts,domain,cells)

labels = get_face_labeling(model)
add_tag_from_tags!(labels,"dirichlet",[1,2,3,5,7])
add_tag_from_tags!(labels,"neumann",[4,6,8])

Ω = Triangulation(model)
Γn = Boundary(model,tags="neumann")
n_Γn = get_normal_vector(Γn)

k = 2
u((x,y)) = (x+y)^k
f(x) = -Δ(u,x)
g = n_Γn(u)

reffe = ReferenceFE(lagrangian,Float64,k)
V = TestFESpace(model,reffe,dirichlet_tags="dirichlet")
U = TrialFESpace(u,V)

= Measure(Ω,2*k)
dΓn = Measure(Γn,2*k)

a(u,v) = ( (v)(u) )dΩ
l(v) = ( v*f )dΩ + ( v*g )dΓn
op = AffineFEOperator(a,l,U,V)

ls = PETScLinearSolver()
fels = LinearFESolver(ls)
uh = solve(fels,op)
eh = u - uh
@test sqrt(sum( (abs2(eh))dΩ )) < 1.0e-9
end
end
1 change: 1 addition & 0 deletions test/mpi/PLaplacianTests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include("../PLaplacianTests.jl")
nparts = (2,2)
prun(main,mpi,nparts)
prun(main,mpi,nparts)
4 changes: 4 additions & 0 deletions test/mpi/PoissonTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include("../PoissonTests.jl")
nparts = (2,2)
prun(main,mpi,nparts)
prun(main,mpi,nparts)
4 changes: 4 additions & 0 deletions test/mpi/PoissonTestsRun.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PoissonTestsRun
include("mpiexec.jl")
run_mpi_driver(procs=4,file="PoissonTests.jl")
end # module
1 change: 1 addition & 0 deletions test/mpi/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module GridapPETScMPITests
using Test
@time @testset "PartitionedArrays" begin include("PartitionedArraysTestsRun.jl") end
@time @testset "PLaplacianTests" begin include("PLaplacianTestsRun.jl") end
@time @testset "PoissonTests" begin include("PoissonTestsRun.jl") end
end # module

0 comments on commit 3ba0de4

Please sign in to comment.