- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I transformed a code (population simulator) into a DLL that I call from VB. It has been working just fine, but later I discovered that when I run more iterations, I get slightly different results compared to the original .exe. To check this, I made a version without passing any arguments, all variables are given values inside the fortran code, all results are printed to a file by fortran code. I tested this version before transforming the code into DLL (as .exe) and afterwards (as DLL by calling from VB) to find out where the problem might be. Before switching to dll, .exe gave me correct results. After converting to dll I got incorrect results (quite small and like-random differences in all output data). I have 34 subroutines and functions where I just placed this declaration:
!DEC$ ATTRIBUTES DLLEXPORT :: name
and then I have main subroutine that I call from VB and there I placed only this declaration:
!DEC$ ATTRIBUTES DLLEXPORT :: name
!DEC$ ATTRIBUTES ALIAS : 'name':: name
I didn't do anything else than this, except removing all write, stop and pause statements.
Could you, please, be so kind and let me know if you have any idea on what might be wrong?
Thank you very much,
Milan
PS. Is there a list of statments that have to be removed when converting to dll?
!DEC$ ATTRIBUTES DLLEXPORT :: name
and then I have main subroutine that I call from VB and there I placed only this declaration:
!DEC$ ATTRIBUTES DLLEXPORT :: name
!DEC$ ATTRIBUTES ALIAS : 'name':: name
I didn't do anything else than this, except removing all write, stop and pause statements.
Could you, please, be so kind and let me know if you have any idea on what might be wrong?
Thank you very much,
Milan
PS. Is there a list of statments that have to be removed when converting to dll?
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So I made some additional testing. In the population simulator I use random number generator based on the RAN2 algorithm given by: Press,W.H.,... 1986. Numerical recipes: the art of scientific computing. Cambridge Univ. Press, Cambridge, UK.
I made a simplified test with "Call RANDOM_NUMBER". Here is the code converted to DLL:
SUBROUTINE pokus
!DEC$ ATTRIBUTES DLLEXPORT :: pokus
!DEC$ ATTRIBUTES ALIAS : 'pokus' :: pokus
REAL*8 :: array1(5000000)
REAL*8 :: sum
REAL*8 :: avg
REAL*8 :: sqd
REAL*8 :: sumsqd
REAL*8 :: var
INTEGER :: number
array1 = 0.00000
sum = 0.00000
avg = 0.00000
sqd = 0.00000
sumsqd = 0.00000
var = 0.00000
CALL RANDOM_NUMBER(array1)
DO i = 1, 5000000
sum = sum + array1(i)
END DO
avg = sum / 5000000
DO i = 1, 5000000
sqd = (array1(i) - avg)**2
sumsqd = sumsqd + sqd
END DO
var = sumsqd / (5000000 - 1)
OPEN(UNIT = 1, FILE = 'D:/RANDOM_NUMBERS/STATISTICS',
+ STATUS = 'REPLACE')
WRITE(1,*) 'Average = ', avg, 'Variance = ', var
CLOSE(1)
END SUBROUTINE pokus
I made a comparison of this dll with the original code (.exe) and here are the results:
MEAN:
.exe 0.500019806620702
.dll 0.500019806620667
VARIANCE:
.exe 8.331441406673876E-002
.dll 8.331441406674497E-002
I called the dll above from VBA (Excel).
I think this might explain the difference that I see in my code. Does anyone know what is the reason for this difference?
Thanks,
Milan
I made a simplified test with "Call RANDOM_NUMBER". Here is the code converted to DLL:
SUBROUTINE pokus
!DEC$ ATTRIBUTES DLLEXPORT :: pokus
!DEC$ ATTRIBUTES ALIAS : 'pokus' :: pokus
REAL*8 :: array1(5000000)
REAL*8 :: sum
REAL*8 :: avg
REAL*8 :: sqd
REAL*8 :: sumsqd
REAL*8 :: var
INTEGER :: number
array1 = 0.00000
sum = 0.00000
avg = 0.00000
sqd = 0.00000
sumsqd = 0.00000
var = 0.00000
CALL RANDOM_NUMBER(array1)
DO i = 1, 5000000
sum = sum + array1(i)
END DO
avg = sum / 5000000
DO i = 1, 5000000
sqd = (array1(i) - avg)**2
sumsqd = sumsqd + sqd
END DO
var = sumsqd / (5000000 - 1)
OPEN(UNIT = 1, FILE = 'D:/RANDOM_NUMBERS/STATISTICS',
+ STATUS = 'REPLACE')
WRITE(1,*) 'Average = ', avg, 'Variance = ', var
CLOSE(1)
END SUBROUTINE pokus
I made a comparison of this dll with the original code (.exe) and here are the results:
MEAN:
.exe 0.500019806620702
.dll 0.500019806620667
VARIANCE:
.exe 8.331441406673876E-002
.dll 8.331441406674497E-002
I called the dll above from VBA (Excel).
I think this might explain the difference that I see in my code. Does anyone know what is the reason for this difference?
Thanks,
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try to initialize your variables as follows:
array1 = 0.0D0
sum = 0.0D0
avg = 0.0D0
sqd = 0.0D0
sumsqd = 0.0D0
var = 0.0D0
instead of = 0.00000
Sabalan.
array1 = 0.0D0
sum = 0.0D0
avg = 0.0D0
sqd = 0.0D0
sumsqd = 0.0D0
var = 0.0D0
instead of = 0.00000
Sabalan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sabalan,
Thanks for your point. I tried it (both .exe and .dll), but the problem still remains. (Results were the same.)
I have no idea where the problem might be. I suppose both .exe and .dll should give the same results. Thanks for any other ideas,
Milan
Thanks for your point. I tried it (both .exe and .dll), but the problem still remains. (Results were the same.)
I have no idea where the problem might be. I suppose both .exe and .dll should give the same results. Thanks for any other ideas,
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can you say one or the other result is 'wrong' when the differences that you show so small as to be insignificant? Since the differences are in quantities generated using a sequence of random numbers they are not surprising, IMHO. That is, unless you are CERTAIN that you always generate the same sequence of pseudorandom numbers each time you call your random-number generator, whether in the DLL or in the .EXE versions of your program, because you always use the same seed etc.
A question for the audience: How can you verify EXACT duplication of the random number
sequence (to machine accuracy) in both DLL and EXE versions?
A question for the audience: How can you verify EXACT duplication of the random number
sequence (to machine accuracy) in both DLL and EXE versions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry Milan, but I couldn't repeat your results for the DLL. I get, with your code, exactly the same value with DLL (both debug and release) as you get from the exe. The only difference occurres when I build and run an exe with release configuration. So, I get:
(debug exe, debug and release DLL)
Average = 0.500019806620702
Variance = 8.331441406673876E-002
but (release exe, no matter use of "Implict None", and 0.D0 to initialize variables)
Average = 0.500019806620654
Variance = 8.331441406674678E-002
which is strange enough to ask Steve why.
(I have CVF 6.6 run at a P4)
Sabalan.
(debug exe, debug and release DLL)
Average = 0.500019806620702
Variance = 8.331441406673876E-002
but (release exe, no matter use of "Implict None", and 0.D0 to initialize variables)
Average = 0.500019806620654
Variance = 8.331441406674678E-002
which is strange enough to ask Steve why.
(I have CVF 6.6 run at a P4)
Sabalan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sabalan,
thank you very much for the information you sent. I get same results for debug and release version. It seems to me we have different settings and since I haven't much experience, I'll ask Compaq Fortran staff for help.
Thank you very much,
Milan
thank you very much for the information you sent. I get same results for debug and release version. It seems to me we have different settings and since I haven't much experience, I'll ask Compaq Fortran staff for help.
Thank you very much,
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi, milan
seems you have a good experience on VB-Fortran mix program. I am now trying to create an VB interface for my MS Powerstation4 fortran code. And I have created an fortran dll using powerstation4. But when I tried call fortran dll file from VB, there is always an error message: Run time erro '453',can't find Dll entry point.
I just want to know that do you have the same trouble before, if so, how did you solve it. If not, could you please tell me some details about how you creat a dll file. Since I am not an expert on this, more details will always be better for me.
this is my email: ihere@citiz.net, if you think it's more convinient, you also can write to me.
eager for your response. thanks a lot.
seems you have a good experience on VB-Fortran mix program. I am now trying to create an VB interface for my MS Powerstation4 fortran code. And I have created an fortran dll using powerstation4. But when I tried call fortran dll file from VB, there is always an error message: Run time erro '453',can't find Dll entry point.
I just want to know that do you have the same trouble before, if so, how did you solve it. If not, could you please tell me some details about how you creat a dll file. Since I am not an expert on this, more details will always be better for me.
this is my email: ihere@citiz.net, if you think it's more convinient, you also can write to me.
eager for your response. thanks a lot.

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