The omp atomic directive identifies a specific memory location that must be updated atomically and not be exposed to multiple, simultaneous writing threads.
>>-#--pragma--omp atomic--+-----------+------------------------>< '-statement-'
| statement | Conditions |
|---|---|
| x bin_op = expr | where:
|
| x++ | |
| ++x | |
| x-- | |
| --x |
Load and store operations are atomic only for object x. Evaluation of expr is not atomic.
All atomic references to a given object in your program must have a compatible type.
Objects that can be updated in parallel and may be subject to race conditions should be protected with the omp atomic directive.
extern float x[], *p = x, y;
/* Protect against race conditions among multiple updates. */ #pragma omp atomic x[index[i]] += y;
/* Protect against races with updates through x. */ #pragma omp atomic p[i] -= 1.0f;