renaming Call -> Task (#70)

This commit is contained in:
Robert Nishihara
2016-05-26 16:33:30 -07:00
committed by Philipp Moritz
parent 7bfc070e29
commit 23d202bb73
12 changed files with 116 additions and 116 deletions
+4 -4
View File
@@ -29,11 +29,11 @@ def deserialize(worker_capsule, capsule):
primitive_obj = orchpy.lib.deserialize_object(worker_capsule, capsule)
return from_primitive(primitive_obj)
def serialize_call(worker_capsule, func_name, args):
def serialize_task(worker_capsule, func_name, args):
primitive_args = [(arg if isinstance(arg, orchpy.lib.ObjRef) else to_primitive(arg)) for arg in args]
return orchpy.lib.serialize_call(worker_capsule, func_name, primitive_args)
return orchpy.lib.serialize_task(worker_capsule, func_name, primitive_args)
def deserialize_call(worker_capsule, call):
func_name, primitive_args, return_objrefs = orchpy.lib.deserialize_call(worker_capsule, call)
def deserialize_task(worker_capsule, task):
func_name, primitive_args, return_objrefs = orchpy.lib.deserialize_task(worker_capsule, task)
args = [(arg if isinstance(arg, orchpy.lib.ObjRef) else from_primitive(arg)) for arg in primitive_args]
return func_name, args, return_objrefs
+8 -8
View File
@@ -43,10 +43,10 @@ class Worker(object):
orchpy.lib.register_function(self.handle, function.func_name, len(function.return_types))
self.functions[function.func_name] = function
def remote_call(self, func_name, args):
def submit_task(self, func_name, args):
"""Tell the scheduler to schedule the execution of the function with name `func_name` with arguments `args`. Retrieve object references for the outputs of the function from the scheduler and immediately return them."""
call_capsule = serialization.serialize_call(self.handle, func_name, args)
objrefs = orchpy.lib.remote_call(self.handle, call_capsule)
task_capsule = serialization.serialize_task(self.handle, func_name, args)
objrefs = orchpy.lib.submit_task(self.handle, task_capsule)
return objrefs
# We make `global_worker` a global variable so that there is one worker per worker process.
@@ -86,15 +86,15 @@ def main_loop(worker=global_worker):
if not orchpy.lib.connected(worker.handle):
raise Exception("Worker is attempting to enter main_loop but has not been connected yet.")
orchpy.lib.start_worker_service(worker.handle)
def process_call(call): # wrapping these calls in a function should cause the local variables to go out of scope more quickly, which is useful for inspecting reference counts
func_name, args, return_objrefs = serialization.deserialize_call(worker.handle, call)
def process_task(task): # wrapping these lines in a function should cause the local variables to go out of scope more quickly, which is useful for inspecting reference counts
func_name, args, return_objrefs = serialization.deserialize_task(worker.handle, task)
arguments = get_arguments_for_execution(worker.functions[func_name], args, worker) # get args from objstore
outputs = worker.functions[func_name].executor(arguments) # execute the function
store_outputs_in_objstore(return_objrefs, outputs, worker) # store output in local object store
orchpy.lib.notify_task_completed(worker.handle) # notify the scheduler that the task has completed
while True:
call = orchpy.lib.wait_for_next_task(worker.handle)
process_call(call)
task = orchpy.lib.wait_for_next_task(worker.handle)
process_task(task)
def distributed(arg_types, return_types, worker=global_worker):
def distributed_decorator(func):
@@ -108,7 +108,7 @@ def distributed(arg_types, return_types, worker=global_worker):
def func_call(*args):
"""This is what gets run immediately when a worker calls a distributed function."""
check_arguments(func_call, list(args)) # throws an exception if args are invalid
objrefs = worker.remote_call(func_call.func_name, list(args))
objrefs = worker.submit_task(func_call.func_name, list(args))
return objrefs[0] if len(objrefs) == 1 else objrefs
func_call.func_name = "{}.{}".format(func.__module__, func.__name__)
func_call.executor = func_executor