From e67bbc4bd42f259d1beb23aba0f59f74cf343f9e Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Sat, 4 Nov 2023 10:30:09 -0400 Subject: [PATCH] Support manually closing and lmp instance (#36) * Support manually closing and lmp instance * Update src/LAMMPS.jl * Update src/LAMMPS.jl * update CI * Update src/LAMMPS.jl * Update .github/workflows/CI.yml --- .github/workflows/CI.yml | 12 +++--------- .github/workflows/Documentation.yml | 9 +-------- Project.toml | 4 ++-- src/LAMMPS.jl | 18 ++++++++++++++---- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e21a0d6..2c8546f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,7 +13,9 @@ jobs: fail-fast: false matrix: version: - - "1.6" + - "1.8" + - "1.9" + - "~1.10.0-0" - "nightly" os: - ubuntu-latest @@ -37,14 +39,6 @@ jobs: ${{ runner.os }}-test-${{ env.cache-name }}- ${{ runner.os }}-test- ${{ runner.os }}- - - name: add CESMIX registry - run: | - julia -e ' - using Pkg - Pkg.Registry.add("General") - Pkg.Registry.add(RegistrySpec(url = "https://github.com/cesmix-mit/CESMIX.git")) - ' - shell: bash - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml index a0210cb..ecc3697 100644 --- a/.github/workflows/Documentation.yml +++ b/.github/workflows/Documentation.yml @@ -13,14 +13,7 @@ jobs: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: - version: "1.6" - - name: add CESMIX registry - run: | - julia -e ' - using Pkg - Pkg.Registry.add("General") - Pkg.Registry.add(RegistrySpec(url = "https://github.com/cesmix-mit/CESMIX.git")) - ' + version: "1.8" shell: bash - name: instantiate docs run: | diff --git a/Project.toml b/Project.toml index 4e6835b..20cac21 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LAMMPS" uuid = "ee2e13b9-eee9-4449-aafa-cfa6a2dbe14d" authors = ["Valentin Churavy "] -version = "0.2.2" +version = "0.3.0" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" @@ -15,4 +15,4 @@ CEnum = "0.4" LAMMPS_jll = "2.4" Preferences = "1" MPI = "0.20" -julia = "1.6" +julia = "1.8" diff --git a/src/LAMMPS.jl b/src/LAMMPS.jl index 09fcf6a..c0a2cbc 100644 --- a/src/LAMMPS.jl +++ b/src/LAMMPS.jl @@ -48,7 +48,7 @@ function set_library!(path) end mutable struct LMP - handle::Ptr{Cvoid} + @atomic handle::Ptr{Cvoid} function LMP(args::Vector{String}=String[], comm::Union{Nothing, MPI.Comm}=nothing) if isempty(args) @@ -71,14 +71,24 @@ mutable struct LMP end this = new(handle) - finalizer(this) do this - API.lammps_close(this) - end + finalizer(close!, this) return this end end Base.unsafe_convert(::Type{Ptr{Cvoid}}, lmp::LMP) = lmp.handle +""" + close!(lmp::LMP) + +Shutdown an LMP instance. +""" +function close!(lmp::LMP) + handle = @atomicswap lmp.handle = C_NULL + if handle !== C_NULL + API.lammps_close(handle) + end +end + function LMP(f::Function, args=String[], comm=nothing) lmp = LMP(args, comm) f(lmp)