Atomic Operations
If, as in the example above, our critical section is a single assignment, OpenMP provides a potentially more efficient way of protecting this.
OpenMP provides an atomic directive which, like critical, specifies the next statement must be done by one thread at a time:
#pragma omp atomic global_data++;
Unlike a critical directive:
The statement under the directive can only be a single C assignment statement. It can be of the form: x++, ++x, x-- or --x. It can also be of the form x OP= expression where OP is some binary operator. No other statement is allowed. The motivation for the atomic directive is that some processors provide single instructions for operations such as x++. These are called Fetch-and-add instructions.
As a rule, if your critical section can be done in an atomic directive, it should. It will not be slower, and might be faster.