-
-
Save robertnishihara/23173a264206623347ade31ea44f4dc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ray | |
import time | |
# Start Ray. | |
ray.init() | |
@ray.remote | |
def f(x): | |
time.sleep(1) | |
return x | |
# Start 4 tasks in parallel. | |
result_ids = [] | |
for i in range(4): | |
result_ids.append(f.remote(i)) | |
# Wait for the tasks to complete and retrieve the results. | |
# With at least 4 cores, this will take 1 second. | |
results = ray.get(result_ids) # [0, 1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment