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

Indices zero based or one based?

Philip_B_
Beginner
1,332 Views

Are indices in the Intel MKL BLAS and LAPACK function zero-based or one-based. For example the function idamax I think returns a zero-based argument with MKL CBLAS. However, my experience with Netlib was that this returned a one based index. There are also other functions such as dsyevx that require index arguments and I don't know whether these should be one-based or zero-based.

0 Kudos
1 Solution
VipinKumar_E_Intel
1,332 Views

Hi Philip,

BLAS level 1 based CBLAS is 0 based indexing and LAPACK and LAPACKE are 1 based indexing.

--Vipin

View solution in original post

0 Kudos
4 Replies
mecej4
Honored Contributor III
1,332 Views

The original portable versions of BLAS and Lapack were written in Fortran, and therefore used the traditional 1-based indices of the language. Later, vendor-enhanced versions were supplied in pre-built library form, the sources of some routines written perhaps in assembler or C, but not released to the public. As C gained popularity, CBLAS and C-Lapack were born, and provided 0-based indices as the default or an option.

As of now, in calls to a library routine that is described as suitable for calling from C,C++,C# and Fortran, it is generally safe to call using 1-base indices. If the library is meant only for use with C/C++/C#, 0-base should be used. A tell-tale sign that a routine can be called with 0-base or 1-base is the presence of an extra (compared to the original BLAS/Lapack version) subroutine argument to specify the type of indexing used. If a library routine does not contain any integer arrays as dummy arguments, it is safe to assume that either 0- or 1-based arrays can be used, because in this case all internally used indices serve only to enable computing the offset from the array base, which is the same whichever convention is used.

Note that the situation is more complicated and your choices more restricted when one or more routine arguments are arrays of rank higher than 1.

When integer arrays containing indices of real array elements are routine arguments (such as an array of pivot indices for matrix factorization, or the iA, jA parts of a CSR or CSC compact matrix) are passed as subroutine arguments, in addition to the 0/1 base question of the integer size (32-bit or 64-bit) becomes a factor.

0 Kudos
VipinKumar_E_Intel
1,333 Views

Hi Philip,

BLAS level 1 based CBLAS is 0 based indexing and LAPACK and LAPACKE are 1 based indexing.

--Vipin

0 Kudos
Jakub_K_2
Beginner
1,332 Views

cblas_izamax() seems to be returning 0-based indexes.
However, MKL online documentation seems to be claiming 1-based indexes:
https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/562204

 

0 Kudos
Gennady_F_Intel
Moderator
1,332 Views

Yakub, could you give the link to this part of online documentation to check this?

0 Kudos
Reply