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

Intializing Variables for Use Across DLL

Aaron_S_1
Beginner
744 Views

All,

I'm working on some legacy software and we have a DLL with one external function: doSomeMath( Data ). Where Data is really multiple arguments with several different large derived types. Internally in doSomeMath the Data is manipulated, memory is allocated and intialization routines are called and there is finally a function computeValues( manipluatedData ). doSomeMath is called several times from a C++ program and each time Data is remanipulated in a non-unique way. What would be the best way to make a function initializeData( Data ) so that I can call computeValues( ) from the C++? I'd laso think this would be more flexible because I can call computeDifferentValues( ) without any re-initialization.

I can think of returning manipulatedData to the C++ and passing it each time or possibly storing manipulatedData as global variables. If I use the globals approach I'd declare manipulated data with the COMMON attribute, right? The first way seems inefficient, the second way seems unsafe. I'm still new to Fortran and programming in general so any advice is greatly appreciated. Thanks.

0 Kudos
3 Replies
Steven_L_Intel1
Employee
744 Views

If you want to use globals, use module variables rather than COMMON. This will allow you to use allocatable arrays. But consider instead the use of "handles" - pointers to structures where you keep context data that can be passed back and forth. This will permit possible parallelization in the future.

0 Kudos
Aaron_S_1
Beginner
744 Views

Steve,

Thanks for your quick reply. Is the best way to create the handles by returning a C_PTR that points to C_LOC( manipulatedData ) to the C++, then recovering the structure using C_F_POINTER in computeValues( )? Or, if the C++ never needs to manipulate the data, can I just use FORTRAN pointers and the LOC( ) function?

0 Kudos
Steven_L_Intel1
Employee
744 Views

I like the first idea better, whether or not the C++ touches the data. I am not sure what you mean by "FORTRAN pointers" - if you mean the "POINTER (a,b)" syntax, that's an extension.

0 Kudos
Reply