Const correctness

Const correctness

Hello,

This previous question http://software.intel.com/en-us/forums/topic/297849 didn't get any answer. Could someone please tell me why the Sparse BLAS has no const modifiers, whereas the CBLAS is the way it should be (with const modifiers !). It is really "painful" to have to const_cast the parameters at each call to the Sparse BLAS interface.

Thank you.

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

Much of the BLAS, LAPACK and other parts of MKL are based on Fortran sources. A clue to this is the passing of arguments by address instead of value when MKL routines are called from C/C++.  In Fortran 77 and earlier, there was no distinction between input and output arguments of subprograms as far as the language syntax rules were concerned. It was up to the programmer to preserve the contents of input arrays and document such usage.

LAPACKE, on the other hand, provides native C interfaces, and helps with matrix arguments by enabling them to be passed in row-major order.

I checked a thread you've mentioned.

>>...Debugging or proving correctness of code could be more easier...

I don't think that debugging really matters here but I agree that correctness of code could look better. A const is recommended to be used when some variable should not be modified.

Why MKL doesn't use const in declarations of some functions? I think this is a legacy issue.

Do you think there is a change that it will be changed someday, so that CBLAS and Sparse BLAS interfaces match ? (I don't see how you can bring regression by changing const qualifiers, except if you are doing shady things under the hood but I doubt that).

>>...Do you think there is a change that it will be changed someday, so that CBLAS and Sparse BLAS interfaces match?

I think it is possible and you need to make a Feature Request with as better as posiible explanation and example(s).

Quote:

qweasd q. wrote:

Do you think there is a change that it will be changed someday, so that CBLAS and Sparse BLAS interfaces match ? (I don't see how you can bring regression by changing const qualifiers, except if you are doing shady things under the hood but I doubt that).

yes, we have such Feature Request submitted and we will modify these interfaces in the one of the future releases.j

here is the #issue for your reference - DPD200346477

Quote:

Sergey Kostrov wrote:

>>...Do you think there is a change that it will be changed someday, so that CBLAS and Sparse BLAS interfaces match?

I think it is possible and you need to make a Feature Request with as better as posiible explanation and example(s).

Here is one of the simplest example one could think of:

#include "mkl.h"
int main () {

    MKL_INT*              _I;

    MKL_INT*              _J;

    double*               _C;
    double one = 1;

    double zero = 0;

    const MKL_INT n = 50, k = 50;

    double x[n];

    double rhs[n];

    char matdescra[6] = { 'G', '0', '0', 'C', '0', '0' };

    char transa = 'N';

    mkl_dcsrmv(&transa, &n, &k, &one, matdescra, _C, _J, _I, _I + 1, rhs, &one, x);

    // mkl_dcsrmv(&transa, const_cast< int* >(&n), const_cast< int* >(&k), &one, matdescra, _C, _J, _I, _I + 1, rhs, &one, x);

}

Quote:

Gennady Fedorov (Intel) wrote:

here is the #issue for your reference - DPD200346477

Great, thanks.

Still not fixed in latest update. What is the holdup please ?

unfortunatelly , the issue has not been fixed in this update.

Hello,

Is it still planned to fix this (trivial) issue ? Thanks.

Thank you for the last update. My code is much cleaner now ! The reference manual has not been updated accordingly though.

Leave a Comment

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