Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29249 Обсуждение

Mapping Shared Memory from C++

Merik_G_
Начинающий
5 446Просмотр.

I'm creating a shared memory file mapping in a DLL in C++ and assign it to SM01

extern "C" {

__declspec (dllexport) char *SM01 = NULL;

}

I can use this in another C++ DLL by doing this

extern "C" __declspec(dllimport) char *SM01;

#define abc1 (*(int *)(SM01 + 4))

I can assign abc1 to a value in shared memory.

I would like to do the equivalent in a FORTRAN DLL but it's not working.  Something like this.

USE, INTRINSIC :: ISO_C_BINDING

IMPLICIT NONE

TYPE(C_PTR), BIND(C) :: SM01

SUBROUTINE FORTRAN_LIBRARY()

INTEGER abc1

EQUIVALENCE (abc1,SM01(4))

abc1 = 555

END

 

 

 

0 баллов
23 Ответы
Merik_G_
Начинающий
872Просмотр.

Wow, thanks for finding that.  Maybe that's why the debugger crashes also?

Steve_Lionel
Почетный участник III
872Просмотр.

I didn't see a debugger crash using 17.0.2. The type mismatch alone would not do that, but as I noted earlier there had been an issue with REAL(16) variables in the debugger.

ben_barrowes
Начинающий
872Просмотр.

garylscott wrote:

Of possible (but remote) interest, here is an easy method of creating a shared memory buffer using file mapping, without need for a DLL.  You can share across separate processes (you'll need your own synchronization method, not too hard to do), threads, DLLs, even separate machines with only minor tweaks and additional effort.  This was written in ~1999 for DVF or CVF and may need some tweaks for IVF but that should be fairly minor.  Overhead will average in the nanoseconds as this prevents page swapping as-is (can be easily changed).

http://www.fortranlib.com/ShareBufferWin32.f90

I could provide an update (IVF compatibility, modernize, etc.) if there's any interest.

 

Gary,

I am interested in a IVF update to the shared memory example you posted. Thanks in advance.

Ответить