Intel® C++ Compiler 16.0 User and Reference Guide
Specifies that a structured block should be run in parallel by a team of threads.
#pragma omp parallel [clause, clause, ...] |
structured-block
clause |
Can be one or more of the following:
|
The thread that encounters this pragma constructs a team of threads to execute the structured-block. The thread that encounters the pragma becomes the master thread with a thread number of zero. The remaining threads are assigned unique numbers between 1 and (N-1), where N is the number of threads in the team. The number of threads in the team is constant for the duration of the structured-block.
The following example demonstrates how to use this pragma to create a team of N threads, each with its own private copy of the variables start, end, and tag. Each variable tag is initialized from the encountering thread's value of tag. Each thread executes the code to compute their own starting time and total time and logs those times in the shared array timing:
Example |
---|
#include <omp.h> void compute(int tag) { double timing[n], start, end; #pragma omp parallel private(start, end) firstprivate(tag) num_threads(n) { start = omp_get_wtime(); // some parallel computation using “tag” end = omp_get_wtime(); timing[omp_get_thread_num()] = end – start; } } |