Parallel square roots¶
Submit a batch of math.sqrt calls to Scaler and collect the results.
[ ]:
# Connection settings -- edit these to point at your running scheduler.
SCHEDULER_ADDRESS = "ws://127.0.0.1:2345" # edit me -- supports tcp:// or ws://; only ws:// works in JupyterLite (browser)
# Optional: override the object-storage address advertised by the scheduler
# (useful when the scheduler is behind Docker/Kubernetes port mapping).
OBJECT_STORAGE_ADDRESS = None # edit me -- leave None to use whatever the scheduler advertises
[ ]:
import math
from scaler import Client
with Client(address=SCHEDULER_ADDRESS, object_storage_address=OBJECT_STORAGE_ADDRESS) as client:
futures = [client.submit(math.sqrt, value) for value in range(16)]
results = [future.result() for future in futures]
for value, result in enumerate(results):
print(f"sqrt({value:2d}) = {result:.4f}")