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

Memory Mapped Files

gfaiz
Beginner
870 Views
Hi All!
I'm new to the Fortran world and have inherited some legacy code that needs to be given a bit of updating.
Under the new scheme we need Fortran to access a Memory Mapped File (created by the VB side) and assign variables to memory locations.
I've done a bit of research into this area and know its possible! I was hoping someone out there might be able to point me towards a good sample of how to do this?
So my question is:
-Whats the best way to assign a variableto a memory locationin Fortran?
Thanks for any help.
0 Kudos
2 Replies
TimP
Honored Contributor III
870 Views

-Whats the best way to assign a variableto a memory locationin Fortran?

As the question is phrased, impossible to make satisfactory answer.
A "Cray pointer" or C_PTR may come from another language, if there is compatibility with C, or may be created on the Fortran side by C_LOC for an object with TARGET attribute. By C_F_POINTER you can make a Fortran pointer consistent with the C_PTR.
gfortran, IBM, and ifort public documentation all have useful discussions. It might be "best" to use the features in a manner which is agreed upon by documentation for multiple compilers.
0 Kudos
jimdempseyatthecove
Honored Contributor III
870 Views
Create a user defined type to describe the data layout you intend to use in your memory mapped file.
(you may need multiple user defined types)

Call a C function to map the file and return a pointer to the type.
Call C_F_POINTER to "convert" the C pointer to F pointer to point to your memory mapped file.

Note, it the memory mapped file is an array of REAL, then you do not need a user defined type.
Also, additional work will be required to construct an array descriptor if the shared data is an array of ...
Look in the IVF documentsection under interoperability issues.

Jim Dempsey
0 Kudos
Reply