43 | | = OpenMP 參考資料 = |
| 43 | == Example 2 : Loop work-sharing == |
| 44 | |
| 45 | * 首先從 [https://computing.llnl.gov/tutorials/openMP/exercise.html OpenMP Exercise] 下載 omp_workshare1.c |
| 46 | {{{ |
| 47 | ~$ wget https://computing.llnl.gov/tutorials/openMP/samples/C/omp_workshare1.c |
| 48 | }}} |
| 49 | * 使用 GCC 編譯 omp_workshare1.c |
| 50 | {{{ |
| 51 | ~$ gcc -o omp_workshare1 -fopenmp omp_workshare1.c |
| 52 | }}} |
| 53 | * 執行 omp_workshare1 執行檔 |
| 54 | {{{ |
| 55 | ~$ ./omp_workshare1 |
| 56 | ~$ ./omp_workshare1 |
| 57 | Thread 3 starting... |
| 58 | Thread 1 starting... |
| 59 | Number of threads = 4 |
| 60 | Thread 0 starting... |
| 61 | Thread 0: c[20]= 40.000000 |
| 62 | Thread 0: c[21]= 42.000000 |
| 63 | Thread 0: c[22]= 44.000000 |
| 64 | Thread 0: c[23]= 46.000000 |
| 65 | Thread 0: c[24]= 48.000000 |
| 66 | Thread 0: c[25]= 50.000000 |
| 67 | |
| 68 | ... skipped ... |
| 69 | |
| 70 | Thread 2 starting... |
| 71 | Thread 2: c[90]= 180.000000 |
| 72 | Thread 2: c[91]= 182.000000 |
| 73 | Thread 2: c[92]= 184.000000 |
| 74 | Thread 2: c[93]= 186.000000 |
| 75 | Thread 2: c[94]= 188.000000 |
| 76 | |
| 77 | ... skipped ... |
| 78 | |
| 79 | Thread 3: c[0]= 0.000000 |
| 80 | Thread 3: c[1]= 2.000000 |
| 81 | Thread 3: c[2]= 4.000000 |
| 82 | Thread 3: c[3]= 6.000000 |
| 83 | Thread 3: c[4]= 8.000000 |
| 84 | Thread 3: c[5]= 10.000000 |
| 85 | |
| 86 | ... skipped ... |
| 87 | |
| 88 | Thread 1: c[10]= 20.000000 |
| 89 | Thread 1: c[11]= 22.000000 |
| 90 | Thread 1: c[12]= 24.000000 |
| 91 | Thread 1: c[13]= 26.000000 |
| 92 | Thread 1: c[14]= 28.000000 |
| 93 | |
| 94 | }}} |
| 95 | |
| 96 | == OpenMP 參考資料 == |