Skip to content

Commit

Permalink
make python indexes 0-based and run GC manually
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Aug 21, 2023
1 parent 4a9c098 commit 6260fe4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/examples/CellListMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,41 @@
# Neighboring pairs of a single set of particles
def neighborlist(x, cutoff, unitcell=None) :
x_t = x.transpose()
# Garbage collection must be turned off because it does not
# interact nicely with python objects, which may be cleaned up
# causing memory corruption
jl.GC.enable(False)
nb_list = jl.neighborlist(x_t, cutoff, unitcell=unitcell)
jl.GC.enable(True)
i_inds = np.full((len(nb_list),), 0, dtype=np.int64)
j_inds = np.full((len(nb_list),), 0, dtype=np.int64)
d = np.full((len(nb_list),), 0.0, dtype=np.float64)
jl.copy_to_numpy_arrays(nb_list, i_inds, j_inds, d)
# convert to 0-based indexing
i_inds -= 1
j_inds -= 1
# Run julia garbage collection
jl.seval("nb_list = nothing")
jl.GC.gc()
return i_inds, j_inds, d
# Neighboring pairs of two sets of particles
def neighborlist_cross(x, y, cutoff, unitcell=None) :
x_t = x.transpose()
y_t = y.transpose()
# Garbage collection must be turned off because it does not
# interact nicely with python objects, which may be cleaned up
# causing memory corruption
jl.GC.enable(False)
nb_list = jl.neighborlist(x_t, y_t, cutoff, unitcell=unitcell)
jl.GC.enable(True)
i_inds = np.full((len(nb_list),), 0, dtype=np.int64)
j_inds = np.full((len(nb_list),), 0, dtype=np.int64)
d = np.full((len(nb_list),), 0.0, dtype=np.float64)
jl.copy_to_numpy_arrays(nb_list, i_inds, j_inds, d)
# convert to 0-based indexing
i_inds -= 1
j_inds -= 1
# Run julia garbage collection
jl.seval("nb_list = nothing")
jl.GC.gc()
return i_inds, j_inds, d

0 comments on commit 6260fe4

Please sign in to comment.