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

Calling mkl LAPACK routines from c++

gpwr9k5
Beginner
356 Views
As I understand, the LAPACK routines are written in Fortran, but can be called from a c++ program. I found some general guidelines explaining the differences in how matrices are stored in Fortran vs c++. I found the following guidelines:
- Pass variables by address as opposed to pass by value.
- Store your data in Fortran style, that is, column-major rather than row-major order.
For example, if a two-dimensional matrix A of size m x n is stored densely in a one-dimensional array B, you can access a matrix element like this:

A = B[i*n+j] in C (i=0, ... , m-1, j=0, ... , n-1)

A(i,j) = B(j*m+i) in Fortran (i=1, ... , m, j=1, ... , n).


My questions are
1. If I store a symmetrical matrix in a packed format by columns, the rersulting vector should be the same in both C++ and Fortran styles. Right?
2. Do I have to shift the elements of the packed matrix so that the first lement has an index 1 before I call a LAPACK routine (for example, dpptrf - Cholesky factorization)?
Thanks.
0 Kudos
1 Reply
jaewonj
Novice
356 Views
Quoting - gpwr9k5
As I understand, the LAPACK routines are written in Fortran, but can be called from a c++ program. I found some general guidelines explaining the differences in how matrices are stored in Fortran vs c++. I found the following guidelines:
- Pass variables by address as opposed to pass by value.
- Store your data in Fortran style, that is, column-major rather than row-major order.
For example, if a two-dimensional matrix A of size m x n is stored densely in a one-dimensional array B, you can access a matrix element like this:

A = B[i*n+j] in C (i=0, ... , m-1, j=0, ... , n-1)

A(i,j) = B(j*m+i) in Fortran (i=1, ... , m, j=1, ... , n).


My questions are
1. If I store a symmetrical matrix in a packed format by columns, the rersulting vector should be the same in both C++ and Fortran styles. Right?
2. Do I have to shift the elements of the packed matrix so that the first lement has an index 1 before I call a LAPACK routine (for example, dpptrf - Cholesky factorization)?
Thanks.

1. If I store a symmetrical matrix in a packed format by columns, the rersulting vector should be the same in both C++ and Fortran styles. Right?

-- Yes, you're right.

2. Do I have to shift the elements of the packed matrix so that the first lement has an index 1 before I call a LAPACK routine (for example, dpptrf - Cholesky factorization)?

-- No, you don't need to.

0 Kudos
Reply