C call Fortan, column major
Hello,
I thought I understood the issue of "column major" in Fortran, and "row major" in C. But after a test, I got confused. I appreciate if you can help.
Following is just a simple example illustrate the issue.
I have a C program, I want to call PDSYEV to get eigenvectors of a matrix M.
Assuming M is a 3X3 matrix.
In C program, I created a 1D array: A[9] = {1, 4, 5, 0, 2, 6, 0, 0, 3}, then I called PDSYEV_ using A as input matrix, and using upper triangle by the letter 'U'.
Because Fortran is "column major", which means in memory adjacent element belong to same column (ignore those on boundary). So if I write in 2D format, A should be the matrix like:
1 0 0
4 2 0
5 6 3
For better reference, let's call the above matrix M1.
By using upper triangle for the eigenvalue problem, all those 4, 5, 6 elements should be ignored, and I should get eigenvalue 1, 2, and 3.
However, I got eigenvalues: -3.66868, -2.50729, 12.176
which are the eigenvalues of the matrix (if only consider upper triangle)
1 4 5
0 2 6
0 0 3
Let's call this matrix M2.
===
To recap,
By definition of "column major", my 1D array should represent M1,
but the ScaLapack routine gave eigenvalue of M2.
What is wrong here?
I thought I understood the issue of "column major" in Fortran, and "row major" in C. But after a test, I got confused. I appreciate if you can help.
Following is just a simple example illustrate the issue.
I have a C program, I want to call PDSYEV to get eigenvectors of a matrix M.
Assuming M is a 3X3 matrix.
In C program, I created a 1D array: A[9] = {1, 4, 5, 0, 2, 6, 0, 0, 3}, then I called PDSYEV_ using A as input matrix, and using upper triangle by the letter 'U'.
Because Fortran is "column major", which means in memory adjacent element belong to same column (ignore those on boundary). So if I write in 2D format, A should be the matrix like:
1 0 0
4 2 0
5 6 3
For better reference, let's call the above matrix M1.
By using upper triangle for the eigenvalue problem, all those 4, 5, 6 elements should be ignored, and I should get eigenvalue 1, 2, and 3.
However, I got eigenvalues: -3.66868, -2.50729, 12.176
which are the eigenvalues of the matrix (if only consider upper triangle)
1 4 5
0 2 6
0 0 3
Let's call this matrix M2.
===
To recap,
By definition of "column major", my 1D array should represent M1,
but the ScaLapack routine gave eigenvalue of M2.
What is wrong here?