[[PageOutline]]
◢ <[wiki:YMU110509/Lab1 實作一]> | <[wiki:YMU110509 回課程大綱]> ▲ | <[wiki:YMU110509/Lab3 實作三]> ◣
= 實作二 =
{{{
#!html
多核心程式設計 : OpenMP
Multi-Cores Programming : OpenMP
}}}
* GCC 4.2 以上版本就有支援 OpenMP 了....用 "gcc '''-fopenmp'''" 就可以編譯
= Example 1 : HelloWorld ==
* 首先從 [https://computing.llnl.gov/tutorials/openMP/exercise.html OpenMP Exercise] 下載 omp_hello.c
{{{
~$ wget https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c
}}}
* 確認目前 gcc 版本,須大於 4.2 以後的版本
{{{
~$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
}}}
* 使用 GCC 編譯 omp_hello.c
{{{
~$ gcc -o omp_hello -fopenmp omp_hello.c
}}}
* 執行 omp_hello 執行檔
{{{
~$ ./omp_hello
Hello World from thread = 2
Hello World from thread = 3
Hello World from thread = 0
Number of threads = 4
Hello World from thread = 1
}}}
= OpenMP 參考資料 =
* 多核心平行化程式設計 Multi-Cores Programming
* <官網> [https://computing.llnl.gov/tutorials/openMP/ OpenMP Tutorial]
* <官網> [https://computing.llnl.gov/tutorials/openMP/exercise.html OpenMP Exercise]
* [http://www.nersc.gov/nusers/help/tutorials/openmp/ OpenMP Tutorial] at National Energy Research Scientific Computing Center (NERSC)
* [http://kheresy.wordpress.com/2006/06/09/%E7%B0%A1%E6%98%93%E7%9A%84%E7%A8%8B%E5%BC%8F%E5%B9%B3%E8%A1%8C%E5%8C%96%E6%96%B9%E6%B3%95%EF%BC%8Dopenmp%EF%BC%88%E4%B8%80%EF%BC%89%E7%B0%A1%E4%BB%8B/ 簡易的程式平行化方法-OpenMP(一)簡介]
* [http://kheresy.wordpress.com/2006/09/13/%E7%B0%A1%E6%98%93%E7%9A%84%E7%A8%8B%E5%BC%8F%E5%B9%B3%E8%A1%8C%E5%8C%96%EF%BC%8Dopenmp%EF%BC%88%E4%BA%8C%EF%BC%89%E8%AA%9E%E6%B3%95%E8%AA%AA%E6%98%8E/ 簡易的程式平行化-OpenMP(二)語法說明]
* [http://kheresy.wordpress.com/2006/09/15/%E7%B0%A1%E6%98%93%E7%9A%84%E7%A8%8B%E5%BC%8F%E5%B9%B3%E8%A1%8C%E5%8C%96%EF%BC%8Dopenmp%EF%BC%88%E4%B8%89%EF%BC%89%E7%AF%84%E4%BE%8B-parallel%E3%80%81section/ 簡易的程式平行化-OpenMP(三)範例 parallel、section]
* [http://kheresy.wordpress.com/2006/09/15/%E7%B0%A1%E6%98%93%E7%9A%84%E7%A8%8B%E5%BC%8F%E5%B9%B3%E8%A1%8C%E5%8C%96%EF%BC%8Dopenmp%EF%BC%88%E5%9B%9B%EF%BC%89%E7%AF%84%E4%BE%8B-for/ 簡易的程式平行化-OpenMP(四)範例 for]
* [http://kheresy.wordpress.com/2006/09/22/%E7%B0%A1%E6%98%93%E7%9A%84%E7%A8%8B%E5%BC%8F%E5%B9%B3%E8%A1%8C%E5%8C%96%EF%BC%8Dopenmp%EF%BC%88%E4%BA%94%EF%BC%89-%E8%AE%8A%E6%95%B8%E7%9A%84%E5%B9%B3%E8%A1%8C%E5%8C%96/ 簡易的程式平行化-OpenMP(五) 變數的平行化]