Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support manually closing and lmp instance #36

Merged
merged 6 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
vchuravy marked this conversation as resolved.
Show resolved Hide resolved
- "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 <[email protected]>"]
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
Loading