Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Results Under Debug x64 Mode #3

Open
breezeBIT opened this issue Jul 16, 2018 · 2 comments
Open

Wrong Results Under Debug x64 Mode #3

breezeBIT opened this issue Jul 16, 2018 · 2 comments
Labels
analyzed Problem has been identified but no solution has been proposed yet wontfix

Comments

@breezeBIT
Copy link

There are different behaviors between debug x64 and release x64 modes for the precompiled windows package version 2.0. For example, suppose you want to evaluate sin(1.0) using DA method and the codes are as follows:

#include
#include "stdafx.h"
#include <DA/dace.h>

using namespace std;
using namespace DACE;

int main(void)
{
DA::init(24, 1);

DA x = DA(1);
DA f = sin(x);

double y = f.evalScalar(1.0);

cout << "DA result is: " << y << endl;
cout << "Exact value is: " << sin(1.0) << endl;

return 0;

}

Suppose the Visual Studio 2017 is used, after compiling and linking, the variable y will have the wrong value 0 under debug x64 mode while it will have the right value of about 0.841471 under the release x64 mode.

@abgandar
Copy link
Collaborator

I finally tried to have a look at this bug. I'm not very familiar with building on Windows, but I believe this is due to the subtleties of C++ DLLs in Windows.

How the DACE DLL is built (Release/RelWithDebInfo or Debug), determines which executables can link with it. This seems to be due to the passing of std:: classes between the DLL and the executable.

With a Debug package installed, building your code from the command line using cl /I "C:\Program Files\DACE 2.0\headers\include" test.cpp "C:\Program Files\DACE 2.0\lib\dace.lib", i.e. with release settings, causes the executable to crash with an out of bounds error inside the evalScalar() call. Debugging it, the problem is that the C++ interface between the code in the executable (evalScalar(), instantiated from a template), and the code in the DLL (eval()) don't seem to use the same interface. In the executable, a temporary std::vector objects created has the correct size (1), but once passed to the DLL, the DLL inside eval() sees them as size 0 and consequently crashes.

When compiling the executable with the same debug parameters as the Debug DLL
cl /I "C:\Program Files\DACE 2.0\headers\include" test.cpp "C:\Program Files\DACE 2.0\lib\dace.lib" /EHsc /Zi /RTC1 /MDd the code runs fine and produces the correct result.

Your problem is the inverse: When the DLL is built as Release, but the executable is built as debug, (as above), the error you describe happens. It is less obvious (as it doesn't crash), but I'm sure the problem stems from the same issue.

I played around a bit, and it seems the exact switch that breaks it is /MDd (something about multithreaded debugging). Compiling the executable without that, but the other debug switches mentioned above, yields correct results when linking with a non-debug DACE DLL.

In short, on Windows it seems the safest way to ensure correct results is to ensure the DACE DLL is only ever linked to the same build type used when building the DLL.
I don't know enough about Windows debug details to suggest a fix for this, although it seems many Windows system libraries come in different versions for the various debug options.

@abgandar abgandar added the analyzed Problem has been identified but no solution has been proposed yet label Sep 17, 2018
@abgandar
Copy link
Collaborator

Whoops, didn't mean to close this issue, but for the time being I don't think we'll have a solution.

@abgandar abgandar reopened this Sep 17, 2018
afossa pushed a commit to afossa/dace that referenced this issue Jun 27, 2024
Start adding docstrings to julia interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzed Problem has been identified but no solution has been proposed yet wontfix
Projects
None yet
Development

No branches or pull requests

2 participants