openmp Simple parallel example

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any openmp Question?