Next: Array Attributes
Up: Arrays
Previous: Declaring Arrays
  Contents
Each element of A
and B is a REAL number, and requires
4 bytes in the memory. The full A and B have 6 components,
hence they require 24 bytes storage.
In F77 A
it is stored in a contiguous 24-byte region in the memory
as follows: A(1) in bytes 1 through 4, A(2)
in bytes 5 through 8, , A(6) in bytes 20 through 24.
B is also stored in a contiguous 24-byte memory
region, but now we have to be careful: the memory model is
one-dimensional, while B is a two-dimensional array.
F90 stores the first column of B first, the second column next
and the third column last. In more detail,
B(1,1) is stored in bytes 1 through 4, B(2,1)
in bytes 5 through 8, B(1,2)
in bytes 9 through 12, B(2,2)
in bytes 13 through 16,
B(1,3) in bytes 17 through 20 and
B(2,3) in bytes 20 through 24.
We say in short that F77 uses storage association.
Unlike F77, F90 does not specify how arrays
are to be organised in memory.
- Advantage. This gives flexibility and allows portability
over different architectures (e.g. on a parallel
computer the compiler may decide to spread a large array over 16 different
memories - this does not violate the F90 standard; the same program may run
efficiently on a single processor machine also).
Consider for example a 4-processor machine. We need to execute
a saxpy operation with a scalar, x(1:1024),y(1:1024),z(1:1024) vectors:
For efficiency the vectors are stored as follows:
on processor 1,
on processor 2,
on processor 3,
on processor 4.
This is an example of data-parallel programming,
where the same operations are executed by different processors on
different data sets.
- Disadvantage.
It is common practice to write C++ programs which
use Fortran numerical libraries, and viceversa, to call
a-different-language library functions in a Fortran program.
Consider a F90 routine with an array argument;
it is very difficult to call it from C++ (or from another language),
since the storage scheme needs to be known in order to properly pass the array
argument.
For input-output purposes an ordering of the elements is needed,
and this is the colum-wise ordering (F77-similar). This ordering does not
imply anything about the storage scheme. For example, if
the statement
print*, b
will produce the output
Similarly,
read*, b
will read in 6 numbers, the elements of B in column-wise order.
Next: Array Attributes
Up: Arrays
Previous: Declaring Arrays
  Contents
Adrian Sandu
2001-08-26