Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return values and async semantics #153

Closed
wlruys opened this issue Jan 11, 2024 · 0 comments
Closed

Return values and async semantics #153

wlruys opened this issue Jan 11, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@wlruys
Copy link
Contributor

wlruys commented Jan 11, 2024

This does not give the expected result.

def run(function: Callable[[], Optional[TaskSpace]]):
    assert callable(function), "The function argument must be callable."

    # Start the Parla runtime.
    with Parla():
        # Create a top-level task to kick off the computation
        @spawn(placement=cpu, vcus=0)
        async def top_level_task():
            # Note that unless function returns a TaskSpace, this will NOT be blocking.
            # If you want to wait on the completion of the tasks launched by function, you must return a TaskSpace that contains their terminal tasks.
            await function()

    # Runtime exists at the end of the context_manager
    # All tasks are guaranteed to be complete at this point

async def value_return():
    import numpy as np

    # Although we typically return values via shared memory
    # Task Futures can be explicitly returned via synchronization

    T = TaskSpace("T")

    for i in range(2):

        @spawn(T[i])
        def t():
            local_array = np.random.rand(3)
            print(f"Task {i} returning: ", local_array, flush=True)
            return local_array

    array1 = await T[0]
    print("Task 0 returned: ", array1, flush=True)
    array2 = await T[1]
    print("Task 1 returned: ", array2, flush=True)
    
    # array3 = await T[2]
    #print("Task 0 returned: ", array1, flush=True)
    #print("Task 1 returned: ", array2, flush=True)
    # print("Task 3 returned: ", array3, flush=True)
    
    return T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants