Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7036 Discussions

Calling Sparce Solver routines from C# fault: MKL-DSS-DSS-Error, Invalid termination level

vd19
Beginner
806 Views

Hello.

I need to use MKL-routines in C# code.

I'd written small C# wrapper over C++ handmade dll. C++ dll's and C# wrapper's code is showing below:

C++ dll's code

#include "stdafx.h"
#include "mkl_dss.h"

extern "C" __declspec(dllexport) _INTEGER_t MKL_dss_create(_MKL_DSS_HANDLE_t &handle, _INTEGER_t opt)
{
_INTEGER_t result = dss_create(handle, opt);
return result;
}

C# wrapper

namespace MKL
{
public class DSS
{
const string MKL_DLL_Name = @"MKL_DSS.dll";

[DllImport(MKL_DLL_Name, CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Unicode)]
private static extern int MKL_dss_create(ref IntPtr handle, ref int opt);

public static int Create(ref IntPtr handle, ref int opt)
{
int res = MKL_dss_create(ref handle, ref opt);
return res;
}
}
}

When I trying to call dss_create wrapper, it aborts with error message "MKL-DSS-DSS-Error, Invalid termination level". What does mean this message? And what I can wrote incorrectly?

Direct calling dss_create from C++ sample works without faults and return error code 0.

Test C# code here:

static void Main(string[] args)
{

IntPtr handle = new IntPtr();

int error, opt = 0;

error = DSS.Create(ref handle, ref opt);

}

C++ test sample:

int _tmain(int argc, _TCHAR* argv[])
{
_MKL_DSS_HANDLE_t handle;
_INTEGER_t error;
_INTEGER_t opt = MKL_DSS_DEFAULTS;

error = MKL_dss_create(handle, opt);

}

I think I have made an error while programming wrapper. But where...?

0 Kudos
1 Solution
Vladimir_Koldakov__I
New Contributor III
806 Views

Hello, vd19,

Why do you pass ref opt? Your C++ wrapper expects for a value while C# wrapper passes a pointer.

Try to remove 'ref' for the 'opt'.

error = DSS.Create(ref handle, opt);

private static extern int MKL_dss_create(ref IntPtr handle, int opt);

public static int Create(ref IntPtr handle, int opt)

int res = MKL_dss_create(ref handle, opt);

Thanks,
Vladimir

View solution in original post

0 Kudos
5 Replies
Vladimir_Koldakov__I
New Contributor III
807 Views

Hello, vd19,

Why do you pass ref opt? Your C++ wrapper expects for a value while C# wrapper passes a pointer.

Try to remove 'ref' for the 'opt'.

error = DSS.Create(ref handle, opt);

private static extern int MKL_dss_create(ref IntPtr handle, int opt);

public static int Create(ref IntPtr handle, int opt)

int res = MKL_dss_create(ref handle, opt);

Thanks,
Vladimir

0 Kudos
vd19
Beginner
806 Views

Vladimir.. You are really right. Thank you.

But I don't understand single error: why program closes during incorrect calling of some procedures of DSS interface? Incorrect calling for example - such as shown above (calling dss_create with error passing 'opt') or below (calling dss_define structure with passing not square matrix).. It's meaning that the procedure returns some error code (MKL_DSS_SUCCESS, MKL_DSS_STATE_ERR, MKL_DSS_NOT_SQUARE), but don't stops with crashing message in console's window.. This error appears as well in C/C++ integrate MKL sample (dss_sym_c.c) if change NCOLS or NROWS from 5 to 6.

I'm using two versions of MKL - 10.2.3.029 and the last 10.2.4.032

Test sample: calling dss_define_structure with passing not square matrix:

const int
nRows = 5,
nCols = 6,
nNonZeros = 9;

int[]
rowIndex = { 1, 6, 7, 8, 9, 10 },
columns = { 1, 2, 3, 4, 5, 2, 3, 4, 5 };

IntPtr handle = new IntPtr();

int error, opt = 0, sym = 536870976;

error = DSS.MKL_dss_create(ref handle, opt);
error = DSS.MKL_dss_define_structure(ref handle, sym, rowIndex, nRows, nCols, columns, nNonZeros);

0 Kudos
Vladimir_Koldakov__I
New Contributor III
806 Views

Hello,

If I understand you right, you have something like:

Run dss example
dss.exe
ret = 0
MKL-DSS-DSS-Error, Not a square matrix
NMAKE : fatal error U1077: 'dss.exe' : return code '0xfffffff8'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files\Microsoft Visual Studio .NET 2003\VC7\BIN\nmake.exe"' : return code '0x2'
Stop.

For the code:


error = DSS.MKL_dss_create(ref handle, opt);
Console.WriteLine("ret = " + error);
error = DSS.MKL_dss_define_structure(ref handle, sym, rowIndex, nRows, nCols, columns, nNonZeros);
Console.WriteLine("ret = " + error);

Ive made the only change in you code, set termination level option (MKL_DSS_TERM_LVL_FATAL)


int error, opt = 1073741872, sym = 536870976;

And then I have:
Run dss example
dss.exe
ret = 0
MKL-DSS-DSS-Error, Not a square matrix
ret = -8


Note, according the mklman.pdf:

The settings for message and termination levels can be set on any call to a DSS routine. However, once set to a particular level, they remain at that level until they are changed in another call to a DSS routine.

Thanks,
Vladimir

0 Kudos
vd19
Beginner
806 Views

Thank you, Vladimir.
Yes, you understand me right. Set 'opt' to MKL_DSS_TERM_LVL_FATAL eliminates this trouble.
What do you think about why MKL integrated sample of using DSS interface contains different checkings of return code after calling different routines?
Default value of 'opt' = MKL_DSS_DEFAULTS which means MKL_DSS_MSG_LVL_WARNING + MKL_DSS_TERM_LVL_ERROR. It is absurd I think, it will never activates if some error appears.

Or may be I am mistaken?

P.S. Whats different between MKL_DSS_TERM_LVL_ERROR andMKL_DSS_TERM_LVL_FATAL?

0 Kudos
Sergey_P_Intel2
Employee
806 Views

Hello!

Let me describe here the difference between MKL_DSS_TERM_LVL_ERROR and MKL_DSS_TERM_LVL_FATAL.

First of all each issue inside DSS interface have its own severity (most of them have "ERROR" severity while several critical ones have "FATAL" severity). For every issue DSS compares issue.severity with message level (defined by MKL_DSS_MSG_LVL_* value) and termination level (defined by MKL_DSS_TERM_LVL_* value).

If issue.severity >= "message level" then some information about this issue is printed by DSS routine.

If issue.severity >= "termination level" then DSS routine calls exit( ) function which terminates current program.

So with MKL_DSS_TERM_LVL_ERROR most issues (which have ERROR or FATAL severity) will result in immediate exit from DSS routine while with MKL_DSS_TERM_LVL_FATAL the exit( ) function will be called only for critical issues (with FATAL severity).

Actually these parameters should be described better in Intel MKL manual.

Regards,

Sergey

0 Kudos
Reply