简体   繁体   中英

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM