Skip to content
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
3 changes: 3 additions & 0 deletions pylammpsmpi/mpi/lmpmpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ def _gather_data_from_all_processors(data):
input_dict = None
input_dict = MPI.COMM_WORLD.bcast(input_dict, root=0)
if input_dict["c"] == "close":
if MPI.COMM_WORLD.rank == 0:
socket.close()
context.term()
job.close()
break
output = select_cmd(input_dict["c"])(input_dict["d"])
Expand Down
11 changes: 9 additions & 2 deletions pylammpsmpi/utils/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ def __init__(
self._oversubscribe = oversubscribe
self._cmdargs = cmdargs
self._socket = None
self._context = None

def start_process(self):
executable = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "../mpi", "lmpmpi.py"
)
context = zmq.Context()
self._socket = context.socket(zmq.PAIR)
self._context = zmq.Context()
self._socket = self._context.socket(zmq.PAIR)
port_selected = self._socket.bind_to_random_port("tcp://*")
cmds = ["mpiexec"]
if self._oversubscribe:
Expand Down Expand Up @@ -677,10 +678,16 @@ def close(self):
self._send(command="close")
try:
self._process.kill()
self._process.stdout.close()
self._process.stdin.close()
self._process.wait()
self._socket.close()
self._context.term()
except AttributeError:
pass
self._process = None
self._socket = None
self._context = None

# TODO
def __del__(self):
Expand Down