etiennepellegrini

5 Reputation

One Badge

11 years, 142 days

MaplePrimes Activity


These are replies submitted by etiennepellegrini

@Carl Love 

 

Thanks! My point is made! This is exactly my problem!


Etienne

Hello,

 

thank you for your answer. However, transposing the matrix does not help with the translation to Fortran. I'll try to explain better with a small example.

Say I have a 3x2 matrix M := [1 2; 3 4; 5 6]. If I translate this to Fortran I get:

M(1,1) = 1; M(1,2) = 2; M(2,1) = 3; M(2,2) = 4, etc...

However, since Fortran is a column-major program, for efficiency purposes (of the access to the memory), it would be much better to have:

M(1,1) = 1; M(2,1) = 3; M(3,1) = 5; M(1,2) = 2; M(2,2) = 4, etc...

Transposing the matrix only changes the matrix itself, it doesn't help with the memory access: the assignment becomes:

M(1,1) = 1; M(1,2) = 3; M(1,3) = 5; M(2,1) = 2, etc... Basically, the matrix is still assigned in a row-major format, and I lose efficiency on my memory access...

Of course on such a small matrix it doesn't change much, but on a bigger matrix when the stride is large (large number of rows) I do lose some efficiency...

So fat the only solution I found was to make a 1D vector from my 2D matrix, so that the columns are written consecutively...

Thanks!

Etienne

Page 1 of 1