- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to convert existing fortran code (with lots of COMMON blocks) to a threadsafe version. Here is the idea:
Each caller calls an initialize method on the fortran DLL which returns a pointer to a user-defined type. This user-type has all the data that goes in the common block.
For subsequent subroutine calls, the caller passed this pointer to the subroutines and the routines then use the data that this pointer points to.
Note that the caller is not going to use the pointer at all - as far as the caller is concerned, it is just a handle.
My questions: Is this a good approach ? Is there a better approach ?
Where can I find sample code or example of such calls ?
Thank you.
vikrantca
I am trying to convert existing fortran code (with lots of COMMON blocks) to a threadsafe version. Here is the idea:
Each caller calls an initialize method on the fortran DLL which returns a pointer to a user-defined type. This user-type has all the data that goes in the common block.
For subsequent subroutine calls, the caller passed this pointer to the subroutines and the routines then use the data that this pointer points to.
Note that the caller is not going to use the pointer at all - as far as the caller is concerned, it is just a handle.
My questions: Is this a good approach ? Is there a better approach ?
Where can I find sample code or example of such calls ?
Thank you.
vikrantca
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Um, we had a similar discussion recently, and the original poster was also named Vikrant. I presume it's you -- or is it just a coincidence?
If this is just supposed to be the continuation of that thread, you can make use of the fact that scalar Fortran pointers in IVF (and most other compilers) are just 4-byte addresses, thus they can be represented by a C type whatever**:
Fortran:
Frankly, I'm not positive if I got the C side right, but I hope you get the idea.
If this is just supposed to be the continuation of that thread, you can make use of the fact that scalar Fortran pointers in IVF (and most other compilers) are just 4-byte addresses, thus they can be represented by a C type whatever**:
Fortran:
subroutine Init (cmnData)C:
type(CmnBlock), pointer:: cmnData
allocate (cmnData)cmnData%whatever = ...
...
end subroutine Init
subroutine DoSomething(cmnData)
type(CmnBlock):: cmnData
...
!do something with cmnData
end subroutine DoSomething
typedef struct {
int dummy
}CmnBlock, lpCmnBlock*;
extern "C" void init(lpCmnBlock*);
extern "C" void dosomething(CmnBlock*);
...
lpCmnBlock handle;
init(&handle);
...
dosomething(handle);Frankly, I'm not positive if I got the C side right, but I hope you get the idea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply Jugoslav.
Yes, the original poster for that discussion was me. We discussed several options in that thread and I implemented all of them, except for the pointer option, which I couldnt get to work.
Hence the second followup question.
Thankyou.
-VA
Yes, the original poster for that discussion was me. We discussed several options in that thread and I implemented all of them, except for the pointer option, which I couldnt get to work.
Hence the second followup question.
Thankyou.
-VA
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page