並列計算とは

データエンジニアリング入門

Vincent Vankrunkelsven

Data Engineer @ DataCamp

並列計算の考え方

現代のデータ処理基盤

  • メモリ
  • 処理能力

考え方

  • タスクをサブタスクに分割
  • 複数コンピュータに分散
  • 協調して完了させる

タスクをサブタスクに分割する図

データエンジニアリング入門

仕立て屋の例

仕立て屋の作業場の図

仕立て屋の運営

目標: シャツ100枚

  • 最も上手な職人: 1枚/20分
  • 他の職人: 1枚/60分

 

複数人での作業 > 最高の一人

データエンジニアリング入門

並列計算の利点

  • 処理能力
  • メモリ: データを分割

 

RAM メモリ チップ: RAM メモリ チップの画像

データエンジニアリング入門

並列計算のリスク

通信によるオーバーヘッド

 

  • タスクは十分に大きい必要
  • 複数の処理ユニットが必要

 

並列化の遅延: 並列化で遅くなる例のプロット

データエンジニアリング入門

 

オリンピック競技の例を示す図

データエンジニアリング入門

multiprocessing.Pool

from multiprocessing import Pool

def take_mean_age(year_and_group): year, group = year_and_group return pd.DataFrame({"Age": group["Age"].mean()}, index=[year])
with Pool(4) as p: results = p.map(take_mean_age, athlete_events.groupby("Year"))
result_df = pd.concat(results)
データエンジニアリング入門

dask

 

import dask.dataframe as dd

# データフレームを4分割 athlete_events_dask = dd.from_pandas(athlete_events, npartitions = 4)
# 各パーティションで並列計算を実行 result_df = athlete_events_dask.groupby('Year').Age.mean().compute()
データエンジニアリング入門

練習してみましょう!

データエンジニアリング入門

Preparing Video For Download...