Function Name | Effect |
---|---|
omp_set_num_threads(int nthread) | Set size of thread team |
int omp_get_num_threads( ) | return size of thread team |
int omp_get_max_threads() | return max size of thread team (typically equal to the number of processors |
int omp_get_thread_num( ) | return thread ID of the thread that calls this function |
int omp_get_num_procs() | return number of processors |
boolean omp_in_parallel() | return TRUE if currently in a PARALLEL segment |
omp_init_lock(omp_lock_t *lock) | Initialize the mutex lock "lock" |
omp_set_lock(omp_lock_t *lock) | Lock the mutex lock "lock" |
omp_unset_lock(omp_lock_t *lock) | Unlock the mutex lock "lock" |
omp_test_lock(omp_lock_t *lock) | Return true if the mutex lock "lock" is locked, returns false otherwise |
#include <iostream.h> #include <omp.h> // Read in OpenMP function prototypes int main(int argc, char *argv[]) { int nthreads, myid; #pragma omp parallel private (nthreads, myid) { /* Every thread does this */ myid = omp_get_thread_num(); cout << "Hello I am thread " << myid << endl; /* Only thread 0 does this */ if (myid == 0) { nthreads = omp_get_num_threads(); cout << "Number of threads = " << nthreads << endl; } } return 0; } |