Failed to call DGELSS from C#

Failed to call DGELSS from C#

Hi,

Trying to access clapack_dgelss from C# and failing. I am using 10.3 Beta version.

When I call this function nothing happens. All output parameters remain at the same values they had before the call. Absolutely nothing. Perhaps I am not calling correctly into the MKL library? I don't know

Attached is a Visual Studio (2005) solution with a very simple example. Note: the sample also calls cblas_dgemm and it works ok. Please copy the redistributables of 10.3 Beta to Bin\\Debug prior to running.

Please advise,
Thanks,
Roy.

14 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Roy,

There are 4 errors in your code.

1.Skipped first argument: int matrix_order

2. Extra INFO argument: c-lapack interface justreturnsINFO as function value

3.If you use WORK array, use _work version of interface: clapack_dgelss_work

4. Use LWORK = -1 to calculate the optimal size of the array work

Below are minimal changes for successful work.

Thanks,

Vladimir

$ diff Program.cs-orig Program.cs
226c226
< int LWORK = 1;
---
> int LWORK = -1;
233c233
< CMKL.dgelss(m_numRows, // M - The number of rows in the A matrix
---
> info = CMKL.dgelss(m_numRows, // M - The number of rows in the A matrix
244,245c244,245
< LWORK, // LWORK - The dimension of the array WORK
< info); // = 0: successful exit
---
> LWORK // LWORK - The dimension of the array WORK
> ); // = 0: successful exit
297c297
< public static void dgelss(int M, int N, int NRHS,
---
> public static int dgelss(int M, int N, int NRHS,
302c302
< int LWORK, [Out] int INFO)
---
> int LWORK)
304c304
< CMKLNative.clapack_dgelss(M, N, NRHS, A, lda, B, ldb, S, RCOND, iRANK, WORK, LWORK, INFO);
---
> return CMKLNative.clapack_dgelss_work(1,M, N, NRHS, A, lda, B, ldb, S, RCOND, iRANK, WORK, LWORK);
340c340
< internal static extern void clapack_dgelss(
---
> internal static extern int clapack_dgelss_work( int matrix_order,
352,353c352,353
< int LWORK, // The dimension of the array WORK
< [Out] int INFO); // = 0: successful exit
---
> int LWORK // The dimension of the array WORK
> ); // = 0: successful exit

Vladimir.Thank ... we're progressing.Nevertheless, even with your points applied, the return value I receive is always -1012.Attached is the updated program ...appreciatevery much your advise.Thanks,
Roy.

Roy,

The beta version has inconsistent C-LAPACK and CBLAS constants. You can find in the MKL/include/mkl_clapack.h header file following values:

#define CLAPACK_ROW_MAJOR 0
#define CLAPACK_COL_MAJOR 1

#define CLAPACK_WORK_MEMORY_ERROR -1010
#define CLAPACK_TRANSPOSE_MEMORY_ERROR -1011
#define CLAPACK_ORDER_ERROR -1012

So -1012 means wrong matrix_order value. Use please 0 instead of CMKL.ORDER.RowMajor.
Also use ref int iRANK for C-declared pointers to scalars: clapack_int* rank => ref int rank.
Below are minimal changes for successful work.

Thanks,
Vladimir

$ diff Program.cs Program.cs-orig

238c238
< 0, // The matrix order - whether the two-dimensional arrays are row-major (CLAPACK_ROW_MAJOR) or column-major (CLAPACK_COL_MAJOR).
---
> CMKL.ORDER.RowMajor, // The matrix order - whether the two-dimensional arrays are row-major (CLAPACK_ROW_MAJOR) or column-major (CLAPACK_COL_MAJOR).
302c302
< return CMKLNative.clapack_dgelss(matrix_order, M, N, NRHS, A, lda, B, ldb, S, RCOND, ref iRANK);
---
> return CMKLNative.clapack_dgelss(matrix_order, M, N, NRHS, A, lda, B, ldb, S, RCOND, iRANK);
356c356
< ref int iRANK); // The effective rank of A, i.e., the number of singular values which are greater than RCOND*S(1)
---
> [Out] int iRANK); // The effective rank of A, i.e., the number of singular values which are greater than RCOND*S(1)

Dear Vladimir,Almost there.Although the function now returns info = 0, the results themselves are not correct yet.Attached is a zip in which I try to solve the following equation: A X B ------ --- --- 1 2 3 1 17 4 5 6 * 2 = 38 7 8 10 3 63 The results I actually get in X are --> (-8.78 E 275, 38, 63). Notice how the two last elements are actually remnantsof the old B vector.Note: just out ofcuriosity, I did try to give the DGELSS a ColMajor option (although I believe I work in RowMajor). I did get "better" results. X -->(26.333, -9.333, 4.00). Notice how the 4.00 is part of the correct answer, but the other 2 elements are not correct.Please advise,Thanks,Roy.

Guys,Can anyone help on this?I fail to get correct results from DGELSS.Zip file with sample problem (in C#) is attached to previous post.Thanks,
Roy.

Roy, your actual data are

A X B
------ --- ---
1 2 3 1 17
4 5 6 * 2 = 38
7 8 10 4 63

As you use row-major order you should set ldb=1. just replace:

B.Length, // ldb - The leading dimension of the array B

with 1. After that I have:

0.99999999999998823
2.0000000000000044
4.0000000000000044

Also lda should be m_numColumns.

-Vladimir

Thankyou Vladimir.I know understand how to use DGELSS.Please note that the documentation is misleading.m -INTEGER. The number of rows of the matrixA(m0).n -INTEGER. The number of columns of the matrixA(n0).lda -INTEGER. The first dimension ofa; at least max(1,m).ldb -INTEGER. The first dimension ofb; must be at least max(1,m,n).Thanks anyway,Roy.

Roy, thank you for the comments.

Please look at the announcement http://software.intel.com/en-us/articles/c-interface-for-lapack/

You can find there more details in the C interface to LAPACK technical paper, in particular:

LAPACK routines use a stride corresponding to the FORTRAN leading dimension (LDA) with all 2D arrays. We must do the same. For RowMajor matrices, elements within a row are assumed to be contiguous and elements from one row to the next are assumed to be a stride/leading dimension apart.

-Vladimir

Vladimir,

Amazingly, we need to reopen this issue.
We are extremely frustrated!!!

We have upgraded from 10.3 beta to the official 10.3 release version.

Immediately thereafter, our application stopped working. Going back to the sample we sent you (Test_DGELSS.zip) we see an error "Unable to find an entry point named 'clapack_dgelss' in DLL 'mkl_rt'." when we try to call clapack_dgelss.

We also noticed on the 10.3 release notes that the C interface had changed (http://software.intel.com/en-us/articles/c-interface-for-lapack/). Is that related?

Release 10.3 veresion (not working)------------------------------------------mkl_rt.dll 10.3.0.1

Beta 10.3 veresion (working)----------------------------------mkl_rt.dll 10.3.0.0
Please Help ASAP.

Thanks,
Roy.

Roy,
Yes, interface names have been changed.
Please use 10.3 LAPACKE_dgelss instead of 10.3 beta clapack_dgelss.
Thanks,
Vladimir

Vladimir,Thank-you for the quick response.After changing the function name, my application does not show anymore the error it previously shown ("Unable to find an entry point named 'clapack_dgelss' in DLL 'mkl_rt'.").Nevertheless, the return code I receive from the function is -1.I have attached the entire solution so you could have a look.Please check this so we can resolve this issue quickly ... unfortuatly, we are now 3 weeks trying to solve the same problem and frankly, somewhat fed up with it. We seriously consider ditching MKL and finding an alternative solution.Thanks,
Roy.

Attachments: 

AttachmentSize
Download Test_DGELSS.zip7.17 KB

Roy,

Sorry, forgot to say that matrix_order constants have been changed also to the more natural values.

Please replace CMKL.CLAPACK_ORDER.RowMajor with CMKL.ORDER.RowMajor.

Thanks,

Vladimir

Vladimir,Yes ... I have just reached the same conclusion myself.Now, my program is working again (and also the test program - TEST_DGELSS)Thanks for your prompt response,Roy.

Leave a Comment

Please sign in to add a comment. Not a member? Join today