メモリ帯域幅を計測する機会があったので記録として残しておきます。簡単にインストール出来るので試してみてくださいね。
今回使うツールは、「STREAM」です。STREAMはシングル・マルチスレッドに対応しています。同一マシーンで何回も使う事は希なので、使ったら削除出来るように /tmp に STREAM用のディレクトリを作ります。
STREAMはコンパイルが必要ですが簡単に出来るので、コンパイルからSTREAMの実行・削除まで記述しますね。
gccコンパイラーをインストール
STREAMをコンパイルするには、gccコンパイラーが必要なのでインストールします。イントール済みの方はここは飛ばしてください。
// インストール
# apt-get install gcc
STREAMをインストール
メモリの限界を極めたいならマルチスレッドでコンパイルした方が良いですが、通常はシングルスレッドでも十分です。シングル・マルチスレッドの両方を計測したい場合は、シングル・マルチの両方をそのままコンパイルすれば対応できます。下記の5つの手順をそのまま実行するだけ両方対応です!
// STREAM用のディレクトリ作成
# mkdir /tmp/stream
// 移動
# cd /tmp/stream
// STREAMのソースを取得
# wget http://www.cs.virginia.edu/stream/FTP/Code/stream.c
// コンパイル(シングルスレッドの場合)
# gcc -O stream.c -o stream
// コンパイル(マルチスレッドの場合)
# gcc -O -fopenmp stream.c -o stream_openmp
STREAMの実行方法
// シングルスレッドでの実行
# ./stream
// マルチスレッドでの実行(OpenMP)
# ./stream_openmp
// マルチスレッドのスレッド数を指定したい場合(例:3スレッド)
# export OMP_NUM_THREADS=3
# ./stream_openmp
シングルスレッドの実行例
// シングルスレッドでの実行
# ./stream
-------------------------------------------------------------
STREAM version $Revision: 5.10 $
-------------------------------------------------------------
This system uses 8 bytes per array element.
-------------------------------------------------------------
Array size = 10000000 (elements), Offset = 0 (elements)
Memory per array = 76.3 MiB (= 0.1 GiB).
Total memory required = 228.9 MiB (= 0.2 GiB).
Each kernel will be executed 10 times.
The *best* time for each kernel (excluding the first iteration)
will be used to compute the reported bandwidth.
-------------------------------------------------------------
Your clock granularity/precision appears to be 1 microseconds.
Each test below will take on the order of 47430 microseconds.
(= 47430 clock ticks)
Increase the size of the arrays if this shows that
you are not getting at least 20 clock ticks per test.
-------------------------------------------------------------
WARNING -- The above is only a rough guideline.
For best results, please be sure you know the
precision of your system timer.
-------------------------------------------------------------
Function Best Rate MB/s Avg time Min time Max time
Copy: 3828.5 0.042689 0.041792 0.043653
Scale: 3195.6 0.051129 0.050068 0.052513
Add: 4014.4 0.062034 0.059785 0.073144
Triad: 3408.9 0.071900 0.070404 0.074448
-------------------------------------------------------------
Solution Validates: avg error less than 1.000000e-13 on all three arrays
-------------------------------------------------------------
黄色くマークしてある部分がメモリの計測結果です。「Best Rate MB/s」の値に注目。
某VPSでの結果ですが、ハッキリ言って遅い部類です・・・。
STREAM の削除
gccコンパイラーは今後も使う機会があると思うので残しておきます。STREAM だけ削除します。STREAM のディレクトリを削除するだけなので簡単です!
// 別のディレクトリに移動
# cd /
// STREAMの削除
# rm -rf /tmp/stream
