Skip to content

Commit

Permalink
Merge with latest version of main
Browse files Browse the repository at this point in the history
  • Loading branch information
FRUrgorri committed May 27, 2024
2 parents 882ff12 + 0768fc6 commit f6b6d3a
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 95 deletions.
10 changes: 5 additions & 5 deletions src/Solvers/petsc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ function petsc_mumps_setup(ksp)
@check_error_code GridapPETSc.PETSC.PCFactorSetMatSolverType(pc[],GridapPETSc.PETSC.MATSOLVERMUMPS)
@check_error_code GridapPETSc.PETSC.PCFactorSetUpMatSolverType(pc[])
@check_error_code GridapPETSc.PETSC.PCFactorGetMatrix(pc[],mumpsmat)
@check_error_code GridapPETSc.PETSC.MatMumpsSetIcntl(mumpsmat[], 4, 1)
# @check_error_code GridapPETSc.PETSC.MatMumpsSetIcntl(mumpsmat[], 4, 1)
@check_error_code GridapPETSc.PETSC.MatMumpsSetIcntl(mumpsmat[], 7, 0)
@check_error_code GridapPETSc.PETSC.MatMumpsSetIcntl(mumpsmat[], 28, 2)
@check_error_code GridapPETSc.PETSC.MatMumpsSetIcntl(mumpsmat[], 29, 2)
@check_error_code GridapPETSc.PETSC.MatMumpsSetCntl(mumpsmat[], 3, 1.0e-6)
@check_error_code GridapPETSc.PETSC.KSPView(ksp[],C_NULL)
# @check_error_code GridapPETSc.PETSC.MatMumpsSetIcntl(mumpsmat[], 28, 2)
# @check_error_code GridapPETSc.PETSC.MatMumpsSetIcntl(mumpsmat[], 29, 2)
# @check_error_code GridapPETSc.PETSC.MatMumpsSetCntl(mumpsmat[], 3, 1.0e-6)
# @check_error_code GridapPETSc.PETSC.KSPView(ksp[],C_NULL)
end

# Standalone AMG solver, 5 iterations
Expand Down
156 changes: 87 additions & 69 deletions test/mpi/hunt_li2019_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,94 @@ using SparseMatricesCSR

using GridapMHD: hunt

# Li2019, MUMPS for Dj
solver = Dict(
:solver => :li2019,
:matrix_type => SparseMatrixCSR{0,PetscScalar,PetscInt},
:vector_type => Vector{PetscScalar},
:block_solvers => [:petsc_mumps,:petsc_gmres_schwarz,:petsc_cg_jacobi,:petsc_cg_jacobi],
:petsc_options => "-ksp_error_if_not_converged true -ksp_converged_reason"
)
hunt(
nc=(6,6),
np=(2,2),
backend=:mpi,
L=1.0,
B=(0.,50.,0.),
debug=false,
vtk=true,
title="hunt",
solver=solver,
)
function main(parts)

# Li2019, GMRES + Overlapping Additive Schwarz preconditioner for Dj
solver = Dict(
:solver => :li2019,
:matrix_type => SparseMatrixCSR{0,PetscScalar,PetscInt},
:vector_type => Vector{PetscScalar},
:block_solvers => [:petsc_gmres_schwarz,:petsc_gmres_schwarz,:petsc_cg_jacobi,:petsc_cg_jacobi],
:petsc_options => "-ksp_error_if_not_converged true -ksp_converged_reason"
)
hunt(
nc=(4,4),
np=(2,2),
backend=:sequential,
L=1.0,
B=(0.,50.,0.),
debug=false,
vtk=true,
title="hunt",
solver=solver,
)
# Default li2019
hunt(
nc=(4,4),
np=parts,
backend=:mpi,
L=1.0,
B=(0.0, 20.0, 0.0),
nsums=100,
debug=false,
vtk=true,
title="hunt",
solver=:li2019,
)

# Li2019, GMRES + Overlapping Additive Schwarz preconditioner for Dj (tunned by options)
petsc_options = """
-ksp_type gmres
-ksp_rtol 1.0e-5
-ksp_atol 1.0e-14
-ksp_converged_reason
-pc_type asm
-pc_asm_overlap 10
-pc_asm_type restrict
-pc_asm_blocks 32
-sub_ksp_type preonly
-sub_pc_type lu
"""
solver = Dict(
:solver => :li2019,
:matrix_type => SparseMatrixCSR{0,PetscScalar,PetscInt},
:vector_type => Vector{PetscScalar},
:block_solvers => [:petsc_from_options,:petsc_gmres_schwarz,:petsc_cg_jacobi,:petsc_cg_jacobi],
:petsc_options => petsc_options
)
hunt(
nc=(4,4),
np=(2,2),
backend=:sequential,
L=1.0,
B=(0.,50.,0.),
debug=false,
vtk=true,
title="hunt",
solver=solver,
)
# Li2019, MUMPS for Dj
solver = Dict(
:solver => :li2019,
:matrix_type => SparseMatrixCSR{0,PetscScalar,PetscInt},
:vector_type => Vector{PetscScalar},
:block_solvers => [:petsc_mumps, :petsc_gmres_schwarz, :petsc_cg_jacobi, :petsc_cg_jacobi],
:petsc_options => "-ksp_error_if_not_converged true -ksp_converged_reason"
)
hunt(
nc=(6, 6),
np=parts,
backend=:mpi,
L=1.0,
B=(0.0, 50.0, 0.0),
debug=false,
vtk=true,
title="hunt",
solver=solver,
)

# Li2019, GMRES + Overlapping Additive Schwarz preconditioner for Dj
solver = Dict(
:solver => :li2019,
:matrix_type => SparseMatrixCSR{0,PetscScalar,PetscInt},
:vector_type => Vector{PetscScalar},
:block_solvers => [:petsc_gmres_schwarz, :petsc_gmres_schwarz, :petsc_cg_jacobi, :petsc_cg_jacobi],
:petsc_options => "-ksp_error_if_not_converged true -ksp_converged_reason"
)
hunt(
nc=(4, 4),
np=parts,
backend=:sequential,
L=1.0,
B=(0.0, 50.0, 0.0),
debug=false,
vtk=true,
title="hunt",
solver=solver,
)

# Li2019, GMRES + Overlapping Additive Schwarz preconditioner for Dj (tunned by options)
petsc_options = """
-ksp_type gmres
-ksp_rtol 1.0e-5
-ksp_atol 1.0e-14
-ksp_converged_reason
-pc_type asm
-pc_asm_overlap 10
-pc_asm_type restrict
-pc_asm_blocks 32
-sub_ksp_type preonly
-sub_pc_type lu
"""
solver = Dict(
:solver => :li2019,
:matrix_type => SparseMatrixCSR{0,PetscScalar,PetscInt},
:vector_type => Vector{PetscScalar},
:block_solvers => [:petsc_from_options, :petsc_gmres_schwarz, :petsc_cg_jacobi, :petsc_cg_jacobi],
:petsc_options => petsc_options
)
hunt(
nc=(4, 4),
np=parts,
backend=:sequential,
L=1.0,
B=(0.0, 50.0, 0.0),
debug=false,
vtk=true,
title="hunt",
solver=solver,
)

end # main

end # module
26 changes: 14 additions & 12 deletions test/mpi/hunt_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ using SparseMatricesCSR

using GridapMHD: hunt

hunt(
nc=(4,4),
np=(2,2),
backend=:mpi,
L=1.0,
B=(0.,50.,0.),
debug=false,
vtk=true,
title="hunt",
solver=:petsc,
)

function main(parts)
# Default monolithic solver w petsc
hunt(
nc=(4,4),
np=parts,
backend=:mpi,
L=1.0,
B=(0.,50.,0.),
debug=false,
vtk=true,
title="hunt",
solver=:petsc,
)
end

end
22 changes: 13 additions & 9 deletions test/mpi/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ module GridapMHDMPITests
using Test
using MPI


testdir = @__DIR__
istest(f) = endswith(f, ".jl") && !(f=="runtests.jl")
testfiles = sort(filter(istest, readdir(testdir)))
# istest(f) = endswith(f, ".jl") && !(f == "runtests.jl")
# testfiles = sort(filter(istest, readdir(testdir)))

MPI.mpiexec() do cmd
for file in testfiles
path = joinpath(testdir,file)
_cmd = `$(cmd) -np 4 --allow-run-as-root --oversubscribe $(Base.julia_cmd()) --project=. $path`
@show _cmd
run(_cmd)
@test true
function run_test(n, file)
MPI.mpiexec() do cmd
path = joinpath(testdir, file)
_cmd = `$(cmd) -np $n --allow-run-as-root --oversubscribe $(Base.julia_cmd()) --project=. $path`
@show _cmd
run(_cmd)
@test true
end
end

run_test(1,"runtests_body.jl")
# run_test(4,"runtests_body.jl")

end
18 changes: 18 additions & 0 deletions test/mpi/runtests_body.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using MPI

if ! MPI.Initialized()
MPI.Init()
end
if MPI.Comm_size(MPI.COMM_WORLD) == 4
parts=(2,2)
elseif MPI.Comm_size(MPI.COMM_WORLD) == 1
parts=(1,1)
else
MPI.Abort(MPI.COMM_WORLD,0)
end

# include("hunt_tests.jl")
# HuntTestsMPI.main(parts)

include("hunt_li2019_tests.jl")
HuntLi2019TestsMPI.main(parts)
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
using Test

include("seq/runtests.jl")

include("mpi/runtests.jl")

0 comments on commit f6b6d3a

Please sign in to comment.