REAL, DIMENSION (n) :: vec
REAL, DIMENSION(1,n) :: arr1
REAL, DIMENSION(n,1) :: arr2
Does they give the same performance or using the vector is more
efficient?
Thanks,
Tuan.
That cannot be reasonably answered from the data given. The memory
layout is identical and there is no concrete reason why the performance
of any of these should be different from the others. If there is a
difference, it would be only because the compiler didn't simplify the
extra complication that the 2-D forms add.
And, of course, depending on exactly how you use them, you can force
them to be completely different in ways that make everything else
irrelevant. For example, if you call a generic procedure, you might get
a different specific for the 2-D forms than the 1-D one. Those different
specifics need not do anything close to the same thing. One can't make
much in the way of definitive statements about the performance of an
isolated declaration statement, with no information about its use or
context.
There can be reasons to do things like these 2-D forms, for example,
when it is just one special case of something more general. But
generally, go with simplicity where you don't have good reason
otherwise.
*BUT* very, very important caveat. The above answer applies to those
exact declarations. It does not apply to other declarations that you
might think amount to the same thing. If those 1 values are other than
1, or of they are variables that just happen to have the value 1, those
are not equivalent situations.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
Using the vector is quicker than the matrix.
The reason is that elements of the matrix are accessed
by forming a product based on n.
Now, there could be optimisations (if the elements
of the matrix are accessed sequentially) that
eliminate the multiplication.
Generally speaking, the subscript of a matrix is computed
using the formula (c-1)*n + r - 1.
The best way to see whether your compiler improves on
that is to look at the object code.