Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

difference with a vector and a 2D array with first dim's extent

0 views
Skip to first unread message

bio_amateur

unread,
Nov 20, 2009, 1:42:19 PM11/20/09
to
Hi all,
Could you please to tell me if I use a vector (1D array) and a 2D
array whose 1st dim is 1

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.

Richard Maine

unread,
Nov 20, 2009, 2:20:23 PM11/20/09
to
bio_amateur <hoangtron...@gmail.com> wrote:

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

robin

unread,
Nov 21, 2009, 1:27:03 AM11/21/09
to
"bio_amateur" <hoangtron...@gmail.com> wrote in message
news:65c10342-62b6-4346...@g23g2000vbr.googlegroups.com...

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.


0 new messages