user3366782
user3366782

Reputation: 1

link a Fortran function into c++

I want to use a fortran function in my c++ code. This function in fortran finds eigenvectors of a matrix. In the rest of the code I want to use this eigenvectors. There is a problem here and that is: fortran is column major order and c++ is row major order. When I link a fortran function in my c++ code, do I have to use column major method (and assume still I am in fortran) or I have to use row major method when I refer to elements of the eigenvectors? This confuses me.

Thanks

Upvotes: 0

Views: 72

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

You will have to pass the Fortran functions data structures that they understand. If the Fortran code expects col major structures then you must supply col major structures.

Simplistically this is nothing more complex than reversing row and column indices. Commonly a Fortran library will accept a matrix as a linear array of values whose layout is specified in the documentation of the library. Follow that documentation and all will be well.

For instance, perhaps you are dealing with a dense N by N matrix. Then you would be expected to supply an array of length N*N, whose entries are stored at index col*N + row.

Upvotes: 1

Related Questions