Intel® C++ Compiler 16.0 User and Reference Guide
Identifies a point at which the view of the memory by the thread becomes consistent with the memory.
#pragma omp flush [list] |
list |
A comma-delimited list of one or more variables to be flushed. |
Threads sometimes maintain a private view of certain memory locations, for example, by loading data into machine registers. This pragma causes the specified list of variables written by this thread to be forced out of the private view of memory, at the point at which this pragma appears. Likewise, the next read of any of the list of variables by this thread is guaranteed to come from memory, and not from the private view of the thread.
If a list is not specified, the operation is applied to all variables visible to the thread.
Example: Executing one, at most, protected section in a given parallel execution |
---|
#include <omp.h> int a,b,tmp; a = b = 0; #pragma omp parallel num_threads(2) { if (omp_get_thread_num() == 0) { #pragma omp atomic b = 1; #pragma omp flush (a,b) #pragma omp atomic tmp = a; if (tmp == 0) { // protected section 1 } } if (omp_get_thread_num() == 1) { #pragma omp atomic a = 1; #pragma omp flush (a,b) #pragma omp atomic tmp = b; if (tmp == 0) { // protected section 2 } } } |
The following example demonstrates how to use this pragma to guarantee that at most, one of the protected sections will be executed in a given parallel execution.