Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

VOLATILE on POINTER

ereisch
New Contributor II
511 Views

The documentation is a little unclear on this, or perhaps I'm mis-reading it.  If I were to declare a variable as a POINTER, and then mark it as VOLATILE, is this marking the pointer as VOLATILE, or the memory region that it points to?  I need to mark the latter.  In this example, I have a structure, BAR, which I want to be able to grow in size as the program progresses, and I have already mapped the HMM common area to global shared memory between multiple processes, as well as the contents of BAR.  When I expand the array, I call a routine that remaps the new addresses of BAR to global, but since they're in shared memory, I need to mark the entire BAR structure as VOLATILE, not just the pointers.

STRUCTURE   /FOO/
    INTEGER*4   A
    INTEGER*4   B
    INTEGER*4   C
END STRUCTURE

BYTE    BEG_ADR
INTEGER*4    NUM_ALLOCATED
INTEGER*4    INDEX
BYTE    END_ADR
TYPE(FOO), POINTER :: BAR(:)

COMMON/HMM/
&  BEG_ADR,
&  NUM_ALLOCATED,
&  INDEX,
&  BAR,
&  END_ADR
VOLATILE/HMM/
VOLATILE BAR

 

0 Kudos
2 Replies
Hirchert__Kurt_W
New Contributor II
511 Views

According to the description in the standard, it effectively marks both.

[If you think about it, if a compiler has to allow for a change in the address stored in a pointer, that means that the pointer may point to different content making the value of the content different, so marking the address as volatile necessarily makes the content also volatile, but the standard is explicit in saying that both the value the association status may be changed by means not specified in the program.]

0 Kudos
jimdempseyatthecove
Honored Contributor III
511 Views

You will have to be careful in writing your access procedures such that they are thread-safe (inter-process as well as intra-process). Consider what happens when the pointer changes in the middle of:

BAR(I)%A = BAR(I)%B + BAR(I)%C

The A, B and C could potentially be members of different objects. Not to mention the other issue of atomicity.

Jim Dempsey

0 Kudos
Reply