14 | | = OpenMP = |
| 14 | = Example 1 : HelloWorld == |
| 15 | |
| 16 | * 首先從 [https://computing.llnl.gov/tutorials/openMP/exercise.html OpenMP Exercise] 下載 omp_hello.c |
| 17 | {{{ |
| 18 | ~$ wget https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c |
| 19 | }}} |
| 20 | * 確認目前 gcc 版本,須大於 4.2 以後的版本 |
| 21 | {{{ |
| 22 | ~$ gcc -v |
| 23 | Using built-in specs. |
| 24 | Target: x86_64-linux-gnu |
| 25 | 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 |
| 26 | Thread model: posix |
| 27 | gcc version 4.4.5 (Debian 4.4.5-8) |
| 28 | }}} |
| 29 | * 使用 GCC 編譯 omp_hello.c |
| 30 | {{{ |
| 31 | ~$ gcc -o omp_hello -fopenmp omp_hello.c |
| 32 | }}} |
| 33 | * 執行 omp_hello 執行檔 |
| 34 | {{{ |
| 35 | ~$ ./omp_hello |
| 36 | Hello World from thread = 2 |
| 37 | Hello World from thread = 3 |
| 38 | Hello World from thread = 0 |
| 39 | Number of threads = 4 |
| 40 | Hello World from thread = 1 |
| 41 | }}} |
| 42 | |
| 43 | = OpenMP 參考資料 = |