並且程式設計師也可以運用此結構,來個別定義thread的行為.
i.e.
#include <omp.h>
#include <iostream>
using namespace std;
int main() {
#pragma omp parallel
{
cout <<"The parallel region is executed by thread "<<omp_get_thread_num();
if (omp_get_thread_num() == 1) {
cout <<" Thread "<<omp_get_thread_num()<<" does things differently\n";
}
}
return 0;
}
附帶一提parallel region有兩種狀態:active以及inactive.
所謂的active是指有多個thread在執行運算,若只有一個thread在做運算的話就是inactive的狀態.
references:
OpenMP Official Web sites
Using OpenMP: Portable Shared Memory Parallel Programming
沒有留言:
張貼留言