OpenMPの勉強をしました。

OpenMPの勉強をしました。

先日買った C/C++プログラマーのためのOpenMP並列プログラミング第2版のPg.44のPIの計算を試してみました。

1億回の変数書き込み同期のため、スレッドが増えるほど実行時間が長くなっています。

uwhpsc@ubuntu:~/Documents$ export OMP_NUM_THREADS=1
uwhpsc@ubuntu:~/Documents$ ./a.out
PI VALUE  3.1415927
PI Calculation time  2.220000 seconds
uwhpsc@ubuntu:~/Documents$ export OMP_NUM_THREADS=2
uwhpsc@ubuntu:~/Documents$ ./a.out
PI VALUE  3.1415927
PI Calculation time  12.480000 seconds
uwhpsc@ubuntu:~/Documents$ export OMP_NUM_THREADS=3
uwhpsc@ubuntu:~/Documents$ ./a.out
PI VALUE  3.1415927
PI Calculation time  22.820000 seconds