Skip to content
Closed
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
9 changes: 8 additions & 1 deletion pylammpsmpi/wrapper/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def __init__(
log_file=None,
library=None,
diable_log_file=True,
sleep_interval=0.1,
oversubscribe=False,
cmdargs=None,
):
self._logger = logger
self._prism = None
Expand All @@ -45,7 +48,11 @@ def __init__(
)
else:
self._interactive_library = LammpsBase(
cores=self._cores, working_directory=working_directory
cores=self._cores,
oversubscribe=oversubscribe,
working_directory=working_directory,
sleep_interval=sleep_interval,
cmdargs=cmdargs,
)

def interactive_lib_command(self, command):
Expand Down
30 changes: 21 additions & 9 deletions pylammpsmpi/wrapper/concurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import os
from concurrent.futures import Future
from queue import Queue
from queue import Empty, Queue
from time import sleep

from pympipool.shared import (
RaisingThread,
interface_bootup,
Expand All @@ -31,6 +33,7 @@ def execute_async(
cores=1,
oversubscribe=False,
cwd=None,
sleep_interval=0.1,
):
executable = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "mpi", "lmpmpi.py"
Expand All @@ -47,14 +50,20 @@ def execute_async(
),
)
while True:
task_dict = future_queue.get()
if "shutdown" in task_dict.keys() and task_dict["shutdown"]:
interface.shutdown(wait=task_dict["wait"])
break
elif "command" in task_dict.keys() and "future" in task_dict.keys():
f = task_dict.pop("future")
if f.set_running_or_notify_cancel():
f.set_result(interface.send_and_receive_dict(input_dict=task_dict))
try:
task_dict = future_queue.get_nowait()
except Empty:
sleep(sleep_interval)
else:
if "shutdown" in task_dict.keys() and task_dict["shutdown"]:
interface.shutdown(wait=task_dict["wait"])
future_queue.task_done()
break
elif "command" in task_dict.keys() and "future" in task_dict.keys():
f = task_dict.pop("future")
if f.set_running_or_notify_cancel():
f.set_result(interface.send_and_receive_dict(input_dict=task_dict))
future_queue.task_done()


class LammpsConcurrent:
Expand All @@ -64,12 +73,14 @@ def __init__(
oversubscribe=False,
working_directory=".",
cmdargs=None,
sleep_interval=0.1,
):
self.cores = cores
self.working_directory = working_directory
self._future_queue = Queue()
self._process = None
self._oversubscribe = oversubscribe
self._sleep_interval = sleep_interval
self._cmdargs = cmdargs
self._start_process()

Expand All @@ -82,6 +93,7 @@ def _start_process(self):
"cores": self.cores,
"oversubscribe": self._oversubscribe,
"cwd": self.working_directory,
"sleep_interval": self._sleep_interval,
},
)
self._process.start()
Expand Down
2 changes: 2 additions & 0 deletions pylammpsmpi/wrapper/extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def __init__(
client=None,
mode="local",
cmdargs=None,
sleep_interval=0.1,
):
self.cores = cores
self.working_directory = working_directory
Expand All @@ -259,6 +260,7 @@ def __init__(
oversubscribe=self.oversubscribe,
working_directory=self.working_directory,
cmdargs=cmdargs,
sleep_interval=sleep_interval,
)

def __getattr__(self, name):
Expand Down