Pythonで学ぶDaskによる並列プログラミング
James Fulton
Climate Informatics Researcher
dask.delayed() で作成した遅延パイプライン# 既定を使用 result = x.compute()result = dask.compute(x)# スレッドを使用 result = x.compute(scheduler='threads')result = dask.compute(x, scheduler='threads')# プロセスを使用 result = x.compute(scheduler='processes')result = dask.compute(x, scheduler='processes')
from dask.distributed import LocalCluster
cluster = LocalCluster(
processes=True,
n_workers=2,
threads_per_worker=2
)
print(cluster)
LocalCluster(..., workers=2, threads=4, memory=31.38 GiB)
from dask.distributed import LocalCluster
cluster = LocalCluster(
processes=False,
n_workers=2,
threads_per_worker=2
)
print(cluster)
LocalCluster(..., workers=2, threads=4, memory=31.38 GiB)
cluster = LocalCluster(processes=True)
print(cluster)
LocalCluster(..., workers=4 threads=8, memory=31.38 GiB)
cluster = LocalCluster(processes=False)
print(cluster)
LocalCluster(..., workers=1 threads=8, memory=31.38 GiB)
from dask.distributed import Client, LocalCluster
cluster = LocalCluster(
processes=True,
n_workers=4,
threads_per_worker=2
)
client = Client(cluster)
print(client)
<Client: 'tcp://127.0.0.1:61391' processes=4 threads=8, memory=31.38 GiB>
クラスターを作成し、クライアントに渡す
cluster = LocalCluster(
processes=True,
n_workers=4,
threads_per_worker=2
)
client = Client(cluster)
print(client)
<Client: ... processes=4 threads=8, ...>
クライアント作成時にクラスターも自動作成
client = Client(
processes=True,
n_workers=4,
threads_per_worker=2
)
print(client)
<Client: ... processes=4 threads=8, ...>
client = Client(processes=True) # 既定で client を使用 result = x.compute()# 別スケジューラに変更可能 result = x.compute(scheduler='threads')# 明示的に client を使用 result = client.compute(x)
LocalCluster():自分のマシン上のクラスターPythonで学ぶDaskによる並列プログラミング