CD 命令が役立つ可能性がある 1 つの例は、ヒストグラムです。スカラー コードのヒストグラム処理は、次のような単純なループです。
load bin index
load bin count at index
increment bin count
store updated bin count at index
通常、ベクトル内に同じビン インデックスが複数ある可能性があるため、ヒストグラムをベクトル化することはできません。
load vector of N bin indices
perform gathered load using N bin indices to get N bin counts
increment N bin counts
store N updated bin counts using scattered store
ただし、ベクトル内のインデックスのいずれかが同じ場合、競合が発生し、結果のビンの更新が正しくなくなります。
だから、救助へのCDの指示:
load vector of N bin indices
use CD instruction to test for duplicate indices
set mask for all unique indices
while mask not empty
perform masked gathered load using <N bin indices to get <N bin counts
increment <N bin counts
store <N updated bin counts using masked scattered store
remove non-masked indices and update mask
end
実際には、この例は非常に非効率的であり、スカラー コードに勝るものはありませんが、CD 命令を使用する価値があると思われる計算集約型の例は他にもあります。通常、これらはデータ要素が非決定論的な方法で更新されるシミュレーションです。1 つの例 ( LAMMPS Molecular Dynamics Simulatorから) は、JeffersらのKNL 本で参照されています。