Last active
February 13, 2023 08:57
-
-
Save eddiebergman/1719b8e72c93e137009ebcbeea80a60c 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
from dask_jobqueue import SLURMCluster | |
import time | |
from pathlib import Path | |
from concurrent.futures import wait, ALL_COMPLETED | |
def f(x: int) -> int: | |
time.sleep(20) | |
print(f"Done {x}") | |
return x * 2 | |
if __name__ == "__main__": | |
here = Path(__file__).absolute().parent | |
logs = here / "logs-test-dask-slurm" | |
logs.mkdir(exist_ok=True) | |
cluster = SLURMCluster( | |
memory="1GB", | |
processes=1, | |
cores=2, | |
local_directory=here, | |
log_directory=logs, | |
queue="gki_cpu-cascadelake", | |
job_extra_directives=["--time 0-00:01:00"] | |
) | |
print(cluster.job_script()) | |
# Launch 10 workers | |
cluster.scale(jobs=10) | |
client = cluster.get_client() | |
executor = client.get_executor() | |
futures = [executor.submit(f, i) for i in range(30)] | |
finished, unfinished = wait(futures, return_when=ALL_COMPLETED) | |
results = [future.result() for future in finished] | |
print(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the output:
print(cluster.job_script())
print(results)