LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Computations involving Fortran DLLs give different results depending on LW/CVI debugging level.

I have compiled some well-documented and robust Fortran subroutines from Slatec into a DLL. When I call these routines from CVI, the results I get differ from the results produced by pure Fortran code. All reals are defined as double precision (real*8 or double) in both languages, but the results differ at the single precision level. Furthermore, the results from CVI depend on the debugging level and whether or not the program is run as a stand alone executable. Running the program from the project window with debugging level `none' produces different results from a stand alone executable.

In the pure Fortran case, the results are independent of debugging and optimization l
evels and independent of compiler.

Any help would be appreciated.

--Keith
0 Kudos
Message 1 of 4
(3,410 Views)
Keith -

Thanks for taking advantage of the Developer Exchange forum. I have been looking over your situation and I would definitely agree that the behavior you are reporting is strange and unexpected.

I am curious, though, as you mentioned that all reals are defined as doubles in both languages (I'm assuming here that you mean the original Fortran code and the CVI code that is now calling the DLL) but that the results differ at the single precision level. Does this mean that you are casting the data types? If so, where are you doing this (the DLL or the calling program)?

Also, have you been able to reproduce this in another ANSI C compiler?

I would say that the best way to address this problem is likely to write in to support@ni.com. I would consid
er including a CVI project that calls the DLL that you have created, as well as an idea of the results that you are expecting based on the pure Fortran testing. If we are able to reproduce this on our end as well, it will be much easier to identify the exact source of the behavior.

I wish that I had a more concrete solution for you at this moment. However, I feel confident that once we are able to see exactly what is going on, we will be able to provide you with a working solution.

Thanks again for using this forum.

Best Regards,

Greg Wempe
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 4
(3,410 Views)
Greg,
Thanks for answering my inquiry. I sent in more information before I got your reply. I don't know what you mean by casting the data types. I admit that my original statement is not as descriptive as it should have been. The program prints out the results in a fixed (not scientific notation) format with
printf ("%21.14f", varname);
The smallest numbers agree in only the first 6 digits, hence my comment about single precision. The largest numbers agree to 11 digits, still less than 15 for double precision.

As I mentioned in my more recent message, I have tried this with Visual C/C++ and gotten the exact same results as the pure fortran.

I will contact NI support as you suggest if I don't hear anything more.

Thanks again for your suggestion
s.

--Keith
0 Kudos
Message 4 of 4
(3,410 Views)
More on this problem...

Today, I used Microsoft Visual C/C++ 6.0 to compile and link the main C calling program and the Fortran DLL import libraries. Visual C gives me the same results as the pure Fortran code. The exact same code compiled under LW/CVI with CVI include files instead of MVC include files gives wrong answers. I've tried this with CVI versions 5.0 and 5.5 with the same results.

It appears that either there is a problem with CVI's implementation of ANSI C or with how CVI imports from DLLs. I should also mention that CVI reports that it cannot read the import libraries created by Digital Visual Fortran. I had CVI create its own DLL import libraries from header files as instructed in the documentation. Visual C reads the CVI import libraries
with no problems, but does not produce erroneous results.
0 Kudos
Message 3 of 4
(3,410 Views)