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.
|
|
0
|
|
|
|
Reply
|
hoangtrongminhtuan (17)
|
11/20/2009 6:42:19 PM |
|
bio_amateur <hoangtrongminhtuan@gmail.com> wrote:
> 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?
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
|
|
0
|
|
|
|
Reply
|
nospam
|
11/20/2009 7:20:23 PM
|
|
"bio_amateur" <hoangtrongminhtuan@gmail.com> wrote in message
news:65c10342-62b6-4346-b3a2-48a057d4ca1c@g23g2000vbr.googlegroups.com...
| 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?
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
|
|
|
|
Reply
|
robin
|
11/21/2009 6:27:03 AM
|
|
|
2 Replies
103 Views
(page loaded in 0.336 seconds)
Similiar Articles: bitmap as array - comp.graphics.api.opengl... powers of 2)I first read it into an array ... arrays are really 2D. When you declare a 3D array it's ... the code with multi-dim arrays 4 tuples will see no difference. Use of MATLAB fftshift - comp.dspnow, setting that difference aside, the main ... n,k), of a 2 dimensional MATLAB array A is accessed, first n ... have the same shape and origin[] vector as the input arrays. Modifying MEX arguments in place? - comp.soft-sys.matlab ...... mat'}, {'sparse data matrix, array [dim,dim ... See Loren's March 1st, 2007, blog for more details on ... How to return a 2D double array in Mex - comp.soft-sys ... Purpose of construction lines - comp.cad.solidworksFirst, you understand that for feature creation ... as,, you may want to only create a layout sketch, 2D ... sys.matlab ..... not sure I really understand the difference ... How to get envelope from AM signal without phase shift - comp.dsp ...----- > First I should say I am tryting to ... you want to see the result of a difference ... be simulated: Start out with a 2D plane wave propagating in the x direction: s ... Multidimensional Arrays :: Matrices and Arrays (MATLABĀ®)Two-Dimensional Stem Plots Combining Stem Plots with ... Using Scalar Techniques with Vector Data ... Passing a Pointer to the First Element of an Array FORTRAN ARRAYS - Iowa State University... can declare a two dimensional real array ... of the array. Thus the extent of A(100,200) is 100 in the first ... be used as a vector in this routine. Some differences ... 7/25/2012 5:05:45 AM
|