Вопрос

I have been trying to understand the openmp pragmas, does an openmp flush (#pragma omp flush) lead to a cache line flush?

How does that change for an implicit flush?

Это было полезно?

Решение

If you're using a machine with a coherent caches (most mainstream machines) then cache-line flushes generally aren't required, and the flush directive is unlikely to do anything explicit regarding the cache. In a coherent system, anything written to one core's cache is immediately visible to all other cores.

However the FLUSH directive may act as a memory barrier, or fence, and it also forces the compiler to generate store instructions for values which it might have been storing in registers.

There's a good description of the directive here, including this note:

Q17: Is the !$omp flush directive necessary on a cache coherent system?

A17: Yes the flush directive is necessary. Look in the OpenMP specifications for examples of its uses. The directive is necessary to instruct the compiler that the variable must be written to/read from the memory system, i.e. that the variable can not be kept in a local CPU register over the flush "statement" in your code.

Cache coherency makes certain that if one CPU executes a read or write instruction from/to memory, then all other CPUs in the system will get the same value from that memory address when they access it. All caches will show a coherent value. However, in the OpenMP standard there must be a way to instruct the compiler to actually insert the read/write machine instruction and not postpone it. Keeping a variable in a register in a loop is very common when producing efficient machine language code for a loop.

If you're using a machine with noncoherent caches, you're probably working at a supercomputing facility and should consult local experts familiar with your architecture and toolset.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top