diff --git a/src/HYPRE.jl b/src/HYPRE.jl index dc4d997..68a959b 100644 --- a/src/HYPRE.jl +++ b/src/HYPRE.jl @@ -19,6 +19,29 @@ using .LibHYPRE: @check # Internal namespace to hide utility functions include("Internals.jl") + +""" + Init(; finalize_atexit=true) + +Wrapper around `HYPRE_Init`. If `finalize_atexit` is `true` a Julia exit hook is added, +which calls `HYPRE_Finalize`. This method will also call MPI.Init unless MPI is already +initialized. +""" +function Init(; finalize_atexit=true) + if !(MPI.Initialized()) + MPI.Init() + end + # TODO: Check if already initialized? + HYPRE_Init() + if finalize_atexit + # TODO: MPI only calls the finalizer if not exiting due to a Julia exeption. Does + # the same reasoning apply here? + atexit(HYPRE_Finalize) + end + return nothing +end + + ############### # HYPREMatrix # ############### diff --git a/test/runtests.jl b/test/runtests.jl index 71d9e50..ca0cb65 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,8 +10,8 @@ using SparseArrays using SparseMatricesCSR using Test -MPI.Init() -HYPRE_Init() +# Init HYPRE and MPI +HYPRE.Init() @testset "HYPREMatrix" begin H = HYPREMatrix(MPI.COMM_WORLD, 1, 5)