Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

FORTRAN shared module data in a DLL

$
0
0

This topic has appeared in several posts, but I am having trouble making a slightly different implementation work and could use some help.

I have a FORTRAN simulation that must dynamically allocate a very large array of aero data.  The array is too large to statically dimension.  This array is defined in a module and sized using the allocate statement.  I would like move this module definition into a DLL that can then be shared across multiple simulations running in parallel.  The data is read only and the simulations do not interact with each other.

From an example I found in a post, the DLL code is:

     module sharedmemory

          !dec$ attributes dllexport :: darray, dummy

          real, dimension(:), allocatable :: darray

          real :: dummy = 111.1

     end module sharedmemory

     subroutine allocatearray

          !dec$ attributes dllexport :: allocatearray

          use sharedmemory

          allocate( darray(3) )

          return

     end subroutine

 

The first process that makes the call to allocate the memory is:

     program service

          !dec$ attributes dllimport :: allocatearray

          use sharedmemory

          call allocatearray

          ! manipulate the numbers over a period of time

          stop

     end program

The second process that reads the data is:

     program reader

          use sharedmemory

          !print the numbers over a period of time

          stop

     end program

I have changed the properties of both process to use the same run-time library as the DLL, and linker has "/section:.data, RWS" added.

Both processes see the dummy variable; it is statically allocated. Service allocates the array and manipulates it with no problem.  Reader will either show garbage for the darray or throws a seg fault.  If I don't allocate the memory in Service, Reader will throw an error about the pointer not being initialized.  My guess is that, while the pointer variable darray is shared, the data it points to is actually local to the Service process.

How do I get the allocated data shared through the DLL?

 

     Thanks,

     Jim


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>