Skip to content

Commit

Permalink
Support manually closing and lmp instance (#36)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vchuravy authored Nov 4, 2023
1 parent 126d971 commit e67bbc4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jobs:
fail-fast: false
matrix:
version:
- "1.6"
- "1.8"
- "1.9"
- "~1.10.0-0"
- "nightly"
os:
- ubuntu-latest
Expand All @@ -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
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LAMMPS"
uuid = "ee2e13b9-eee9-4449-aafa-cfa6a2dbe14d"
authors = ["Valentin Churavy <v.churavy@gmail.com>"]
version = "0.2.2"
version = "0.3.0"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand All @@ -15,4 +15,4 @@ CEnum = "0.4"
LAMMPS_jll = "2.4"
Preferences = "1"
MPI = "0.20"
julia = "1.6"
julia = "1.8"
18 changes: 14 additions & 4 deletions src/LAMMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit e67bbc4

Please sign in to comment.