You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a new decorator that executes the function in the background.
When a decorated function gets called, it returns immediately, and the computation will be executed in the background using the currently setup BackendEngine.
The return value of the function will behave like a regular value, except that it reading it will block until the computation finishes.
Example:
@delayeddefdelayed_pow(a: float, b: float) ->float:
returnmath.pow(a, b)
# This will compute all the `delayed_pow()` calls in parallel:total_sum=sum([delayed_pow(x, 2) forxinrange(0, 1000)])
# Operators should work tooprint((delayed_pow(2, 2) +delayed_pow(4, 2)) *4)
# Can be used without a decoratora=delayed(math.sqrt)(16)
b=delayed(math.sqrt)(9)
print(a+b)
While being simpler to use that @parfun, it has a few disadvantages:
It does not try to find the optimal partitioning size of the parallelized tasks;
Exceptions are harder to understand, as these will be raised when the function return value is first accessed, not when then function is called.
As Pargraph already has a @delayed decorator, I'm thinking about using a different name. Here are some ideas:
@task;
@parasync;
@parallel_task;
@concurrent_task;
I already have a basic implementation working in new_delayed_api.
The text was updated successfully, but these errors were encountered:
Adding a new decorator that executes the function in the background.
When a decorated function gets called, it returns immediately, and the computation will be executed in the background using the currently setup
BackendEngine
.The return value of the function will behave like a regular value, except that it reading it will block until the computation finishes.
Example:
While being simpler to use that
@parfun
, it has a few disadvantages:As Pargraph already has a
@delayed
decorator, I'm thinking about using a different name. Here are some ideas:@task
;@parasync
;@parallel_task
;@concurrent_task
;I already have a basic implementation working in new_delayed_api.
The text was updated successfully, but these errors were encountered: