Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

View shared memory variables in the debugger

I have the same question that seems to still be a problem in Intel Fortran XE 2016 integrated with Visual Studio 2015.  I create a shared section (memory) in a DLL and change the values via FORTRAN.  The code is working fine; however, when I try to change the value in the debugger, the shared memory does not get written.

 The code for the shared section is this:

extern "C"

{

#pragma data_seg(".MYSEC")

__declspec (dllexport) char abcbuffer[ABCSIZE] = { 0 };

#pragma data_seg()

#pragma comment(linker, "-section:.MYSEC,rws")

}

The code for the FORTRAN program is this:

program FortranExecutable

implicit none

 

INTEGER*4 VAR1

INTEGER*4 VAR2

 

COMMON /ABCBUFFER /

& VAR1,VAR2

!ms$attributes dllimport :: ABCBUFFER

!ms$attributes C, alias : 'abcbuffer' :: ABCBUFFER

PRINT*, VAR1

PRINT*, VAR2

 

VAR1 = 123

VAR2 = 234

 

PRINT*, VAR1

PRINT*, VAR2

 

READ(*,*) VAR1,VAR2

 

end program FortranExecutable

When I run the program I get the following output:

0

0

123

234

When I run the program a second time while the first is still running, you can see that the shared memory is set and I get the following output:

123

234

123

234

Now if I start again and break in the first program before the second set of "prints" and set the value VAR1 to 777, the "prints" will see the new value

0

0

777

234

But if I run the program a second time, the second program does not see the value changed through the debugger and I get the following again:

123

234

123

234

Why is it when the value is changed in the debugger, the second program does not see the change?

I attached the program.

 

 

0 Kudos
1 Reply
Highlighted
Black Belt

I just tried your program

I just tried your program with the integration from the current beta, and I see propagation of changes made in the debugger across two processes.

I would expect that if any level of optimisation was active, your assumptions around how things will be communicated via a shared segment will be invalidated - i.e. the sort of issues that the VOLATILE may help with.  You will also need to be mindful of race conditions - if you have multiple processes accessing the shared memory, how are you synchronising them?
 

0 Kudos