- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- 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
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.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- 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
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page