Topic: Coarray Fortran DLL can be possibly called from C++ or C#
I am trying to understand how a Coarray Fortran DLL can be possibly called from C++ or C#. Do you have any suggestion or example?
Thanks in advanced!
For discussions of all Approximatrix products and related software
You are not logged in. Please login or register.
Approximatrix Forums → User Support → Coarray Fortran DLL can be possibly called from C++ or C#
I am trying to understand how a Coarray Fortran DLL can be possibly called from C++ or C#. Do you have any suggestion or example?
Thanks in advanced!
With Simply Fortran on Windows, the use of coarrays is complicated by the need for the executable to launch in a specialized manner. Coarrays (at least our implementation and most others) rely on multiple images of the executable running in parallel. When a Fortran executable using coarrays starts, our library launches the executable a number of times more (the number of CPU cores present by default) with special command line flags notifying the images of how to communicate with one another. The library hooks into the documented Fortran runtime API to handle startup and information passing.
Launching this coarray program from a DLL would be exceptionally complicated because it needs to actually start additional processes for the Fortran coarray handling. I'm not exactly sure how this situation would be handled from a call originating from a C++ of C# program because it would skip the multiple-image-initialization step.
I think it might be more useful to look at what you wish to achieve. You could have your C++ or C# program launch a Fortran executable that uses coarrays and read results from a file possibly. If you're just looking to perform some parallel computations, OpenMP programming might be somewhat more convenient since it relies only on threads, which wouldn't run into the multiple-image issues I described.
Can you tell us more about what you're trying to achieve? Coarrays aren't necessarily the best answer for parallel computations.
Jeff, Thank for your reply.
My program is DLL implementation, to achieve complex parallelism, we selected Coarray. But we find that no compiler supports running Coarray in a DLL now.
It would be possible to do if you used an external executable rather than a DLL. Unfortunately, Coarray implementations (and compiler support for Coarray implementations) focus on multiple images of a program running. If there were a Coarray implementation that relied on threads rather than separate processes, you'd be able to do what you're suggesting.
The issue is that the compiler we ship, GNU Fortran, assumes that Coarrays, regardless of the implementation, will be using multiple images. This decision isn't arbitrary, though. Many of the assumptions that the compiler itself makes assumes that the program is running in a self-contained image. For example, when a variable has the SAVE attribute, meaning its value will persist across calls to a procedure, Coarray Fortran assumes that the saved value is local to that Coarray worker. Yet the compiler treats it as a special static variable local to that process. If Coarrays relied on threads, every thread, in theory, would see the same value in that variable because it is local to that process, not thread. Those odd, little corners of the language makes implementing Coarrays without multiple processes highly problematic.
Approximatrix Forums → User Support → Coarray Fortran DLL can be possibly called from C++ or C#
Powered by PunBB, supported by Informer Technologies, Inc.