6.7.3 Registers and Compiler Optimizations

Advice to users. All the material in this section is an advice to users.(End of advice to users.)

A coherence problem exists between variables kept in registers and the memory value of these variables. An RMA/ call may access a variable in memory (or cache), while the up-to-date value of this variable is in register. A get will not return the latest variable value, and a put may be overwritten when the register is stored back in memory.

The problem is illustrated by the following code:


		Source of Process1		Source of Process2		Executed inProcess 2

bbbb = 777 buff = 999 reg_A:=999
call MPI_WIN_FENCE call MPI_WIN_FENCE
call MPI_PUT(bbbb stop appl.thread
into buff of process 2) buff:=777 in PUT handler
continue appl.thread
call MPI_WIN_FENCE call MPI_WIN_FENCE
ccc = buff ccc:=reg_A

In this example, variable buff is allocated in the register reg_A and therefore ccc will have the old value of buff and not the new value 777.

This problem, which also afflicts in some cases send/receive communication, is discussed more at length in Section 10.2.2.

MPI-/ implementations will avoid this problem for standard conforming C programs. Many Fortran compilers will avoid this problem, without disabling compiler optimizations. However, in order to avoid register coherence problems in a completely portable manner, users should restrict their use of RMA/ windows to variables stored in COMMON blocks, or to variables that were declared VOLATILE (while VOLATILE is not a standard Fortran declaration, it is supported by many Fortran compilers). Details and an additional solution are discussed in Section 10.2.2, ``A Problem with Register Optimization,'' on page [*]. See also, ``Problems Due to Data Copying and Sequence Association,'' on page [*], for additional Fortran problems.

=chapter6

MPI-Standard for MARMOT