# Clauses

([Main README](README.md))

Clauses can be added in the end of a pragma to specify construct specifics or usage of variables.

**collapse(n)**  
Collapse *n* nested loops

- Allows for more parallelism if threads are idle otherwise

**private([\<var\>])**  
Specifies that each thread should have its own instance of a variable

**firstprivate([\<var\>])**  
Specfies that each thread should have its own instance of a variable.  
Also initializes the variable with its value, because it exists before the parallel construct.

**lastprivate([\<var\>])**  
Specfies that the enclosing context's version of the variable is set equal to the private version of whichever thread executes the final iteration (do-loop construct) or last section (!$omp section).

**shared([\<var\>])**  
Specifies that one or more variables should be shared among all threads.

**reduction(operation:[\<var\>])**  
Specifies that one or more variables that are private to each thread are the subject of a reduction operation at the end of the parallel region.

**copyin([\<var\>])**  
Allows threads to access the main thread's value, for a threadprivate variable.

**copyprivate([\<var\>])**  
Specifies that one or more variables should be shared among all threads.

**device(device_num:\<val\>)**  
Specify which device should execute the kernel within the pragma.

- Can use omp_get_num_devices() to get the number of non-host devices.
- *device_num:\<val\>* can be used to distribute work amoung multiple devices.
- *ancestor: 1* can be used to specify a region for work on parent device without exiting target.

**if(\<statement\>)**  
Kernel only executes if the statement is true.

- Will be executed as first, regardless of other clauses.

**nowait**  
In standard, all tasks need to completed before going to next kernel. With nowait, the host thread continues while the nowait kernel executes.
