Explore tens of thousands of sets crafted by our community.
OpenMP Directives and Clauses
26
Flashcards
0/26
#pragma omp critical
Purpose: Specifies a region of code that must be executed by only one thread at a time. Usage Example: #pragma omp critical {<protected code block>}
#pragma omp barrier
Purpose: Synchronizes all threads in a team; all must reach this point before any can proceed. Usage Example: #pragma omp parallel {<code block>} #pragma omp barrier
num_threads(n)
Purpose: Specifies the number of threads to use in a parallel region. 'n' is the number of threads. Usage Example: #pragma omp parallel num_threads(n)
#pragma omp parallel
Purpose: Initiates a parallel region by forking multiple threads. Usage Example: #pragma omp parallel {<code block>}
#pragma omp single
Purpose: Specifies a block of code to be run by a single thread, while others wait. Usage Example: #pragma omp parallel { #pragma omp single {<single-thread code>}}
default(shared|none|private|firstprivate)
Purpose: Sets the default data-sharing attributes for variables in a parallel region. Usage Example: #pragma omp parallel default(none)
shared(variable_list)
Purpose: Declares variables to be shared across all threads in a parallel region. Usage Example: #pragma omp parallel shared(counter)
firstprivate(variable_list)
Purpose: Like private, but initializes each thread's variable with the value from the master thread. Usage Example: #pragma omp parallel firstprivate(input_data)
#pragma omp flush
Purpose: Enforces memory consistency by ensuring the visibility of shared variables across threads. Usage Example: #pragma omp flush (variable)
nowait
Purpose: Removes the implicit barrier at the end of a for, single, sections or work-sharing directive. Usage Example: #pragma omp for nowait
#pragma omp sections
Purpose: Divides work into separate sections that may run in parallel. Usage Example: #pragma omp parallel sections { #pragma omp section {<section code>} ... }
schedule(static, chunk_size)
Purpose: In a parallel loop, assigns iterations in contiguous chunks of size 'chunk_size' to each thread ahead of time. Usage Example: #pragma omp for schedule(static, chunk_size)
reduction(operation: variable_list)
Purpose: Performs a reduction on the variables using a specified operation (e.g., +, *, max, min) across threads. Usage Example: #pragma omp parallel for reduction(+:sum)
#pragma omp for
Purpose: Distributes loop iterations among threads in a parallel region. Usage Example: #pragma omp parallel for for(int i = 0; i < N; ++i) {<loop body>}
collapse(n)
Purpose: Combines nested loops to increase the granularity of parallelism. 'n' specifies the number of loops to collapse. Usage Example: #pragma omp parallel for collapse(2) for(int i = 0; i < N; ++i) for(int j = 0; j < M; ++j){<loop body>}
schedule(guided, chunk_size)
Purpose: Similar to dynamic, but the size of chunks decreases over time to handle load balancing as threads become free. Usage Example: #pragma omp for schedule(guided, chunk_size)
private(variable_list)
Purpose: Creates thread-private versions of the variables for each thread in a parallel region. Usage Example: #pragma omp parallel private(x, y)
ordered
Purpose: Specifies that the enclosed loop can execute certain iterations in the original order. Usage Example: #pragma omp parallel for ordered for(int i = 0; i < N; ++i) { #pragma omp ordered {...} }
schedule(auto)
Purpose: Delegates the decision of scheduling to the compiler and runtime system. Usage Example: #pragma omp for schedule(auto)
#pragma omp task
Purpose: Creates an explicit task to be executed by any thread in the team. Usage Example: #pragma omp parallel { #pragma omp task {<code block>}}
schedule(dynamic, chunk_size)
Purpose: In a parallel loop, allows threads to request new chunks as they finish processing old ones. Usage Example: #pragma omp for schedule(dynamic, chunk_size)
#pragma omp atomic
Purpose: Ensures that a specific memory update operation occurs atomically. Usage Example: #pragma omp atomic {<atomic operation>}
#pragma omp master
Purpose: Designates a block to be executed by the master thread only, no barrier at the end. Usage Example: #pragma omp parallel { #pragma omp master {<master thread code>}}
lastprivate(variable_list)
Purpose: Ensures that the var from the sequentially last iteration of the loop is the one that gets written back to the global scope. Usage Example: #pragma omp for lastprivate(latest_value)
#pragma omp taskwait
Purpose: Introduces a point at which the thread will wait for all child tasks to complete. Usage Example: #pragma omp task {<task1>} #pragma omp task {<task2>} #pragma omp taskwait
schedule(runtime)
Purpose: Determines the scheduling based on the environment variable OMP_SCHEDULE. Usage Example: #pragma omp for schedule(runtime)
© Hypatia.Tech. 2024 All rights reserved.