並列処理とベクトル処理の組み合わせ
SIMDの上にスレッド処理を重ねます
「並列処理とベクトル処理の組み合わせ」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Two Kinds of Speed
SIMD packs many values into one core's instruction. Threads spread work across cores. Stacking both gives you the most. ⚡
Outer Layer: Threads
Use parallelize on the outer level so each core owns a chunk of the data. That is the coarse split across cores.
parallelize[do_chunk](workers)Inner Layer: Vectors
Inside each chunk, use vectorize so one core chews through its slice in SIMD packs. That is the fine split per core.
from algorithm import vectorizeImport Both Helpers
Both tools live in the algorithm module, so you can bring them in together and combine them in one function.
from algorithm import parallelize, vectorizeThe Chunk Worker
Each chunk worker computes its start and end, then hands its own slice to vectorize for the SIMD sweep.
fn do_chunk(c: Int):
var start = c * chunkVectorize the Inner Range
Within the worker, call vectorize on just this chunk's length. The SIMD width sets how many lanes run at once.
vectorize[step, width](end - start)Offset Into the Data
The inner step gets a local index, so add the chunk start to reach the right spot in the full array.
fn step[w: Int](i: Int):
out.store[width=w](start + i, ...)Pick the SIMD Width
Match the vector width to your hardware lanes with simdwidthof so each core uses its registers fully.
alias width = simdwidthof[DType.float32]()Cores Times Lanes
The win multiplies: many cores, each doing many lanes per step. That product is why combined code is so fast.
Keep Chunks Independent
This stacking only works because chunks never touch each other's data. Independence keeps the two layers safe.
Measure the Combined Gain
Benchmark scalar, vector-only, and combined versions. The numbers reveal how much each layer contributes.
Quick Check
You combine threads and SIMD on the same workload.
Recap
You wrap parallelize over chunks and call vectorize inside each, offsetting by the chunk start, so cores times lanes multiply your throughput. 🚀
よくある質問
「並列処理とベクトル処理の組み合わせ」レッスンは無料ですか?
はい。「並列処理とベクトル処理の組み合わせ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「並列処理とベクトル処理の組み合わせ」で何を学びますか?
SIMDの上にスレッド処理を重ねます ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「並列処理とベクトル処理の組み合わせ」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- parallelize関数
- 処理のチャンク分割
- 並列処理とベクトル処理の組み合わせ
- データ競合の回避