openmpSimple parallel example


Syntax

  • #pragma omp parallel indicates that the following block shall be executed by all the threads.

  • int omp_get_num_threads (void) : returns the number of the threads working on the parallel region (aka team of threads).

  • int omp_get_thread_num (void) : returns the identifier of the calling thread (ranges from 0 to N-1 where N is bounded to omp_get_num_threads()).

Remarks

You can use the OMP_NUM_THREADS environment variable or the num_threads directive within the #pragma parallel to indicate the number of executing threads for the whole application or for the specified region, respectively.