Skip to content
Open
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
2 changes: 1 addition & 1 deletion charm4py/ray/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .api import get_object_store, init, remote, get, wait, put
from .api import get_object_store, init, remote, get, wait, put, is_initialized, shutdown
13 changes: 12 additions & 1 deletion charm4py/ray/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def init():
charm.thisProxy.updateGlobals({'object_store' : object_store,},
awaitable=True, module_name='charm4py.ray.api').get()

def is_initialized():
# if the object store exists, ray is initialized
if 'object_store' in globals():
return True
else:
return False


def get_object_store():
global object_store
Expand Down Expand Up @@ -103,4 +110,8 @@ def put(obj):
from ..charm import charm
fut = charm.threadMgr.createFuture(store=True)
fut.create_object(obj)
return fut
return fut

def shutdown():
global object_store
del object_store
4 changes: 4 additions & 0 deletions examples/ray/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def add(self, a, b):

def main(args):
ray.init()
assert ray.is_initialized()
# create 3 instances of MyChare, distributed among cores by the runtime
arr = [Compute.remote(i) for i in range(4)]

Expand All @@ -43,6 +44,9 @@ def main(args):
while len(not_ready) > 0:
ready, not_ready = ray.wait(not_ready)
print("Fetched value: ", ray.get(ready))

ray.shutdown()
assert not ray.is_initialized()

exit()

Expand Down