Memory storage of multidimensional arrays in fortran 90

In summary, the conversation discusses the storage of multidimensional arrays in Fortran 90 and whether or not they can be stored non-contiguously in memory. It is mentioned that this may depend on the compiler used, such as ifort or gfortran. However, it is found that Fortran 90 does not impose a specific storage implementation on arrays, but some people claim that the first index is always contiguous. Subarrays with a stride, as well as pointers to such arrays, are not contiguous. Arrays defined with a simple format are usually contiguous. Any additional insights are appreciated.
  • #1
vacuum
77
0
Hello,

I think i heard somewhere that a multidimensional array in fortran 90 may be stored non-contiguously in memory. Is this true? Even if it the size was known at compile time?

If your answer is it depends on a compiler, what about ifort and gfortran?
 
Technology news on Phys.org
  • #2
OK, after some investigation, I found that fortran 90, unlike fortran 77 (and C) does not impose a storage implementation on the arrays. But, according to some people, in all implementations at least the first index is contiguous. What is certainly not contiguous are subarrays chosen with a stride of course (A(1:50:10)), though when used as an argument they are usually copied to a contiguous temporary. The pointers to such arrays are also not contiguous.
If arrays are defined with a simple format, e.g. A(10,20,30), they are, in most (all?) cases contiguous.

Any further comments or clarifications would be welcome.
 

What is a multidimensional array in Fortran 90?

A multidimensional array in Fortran 90 is a data structure that allows for multiple dimensions of data storage. It is made up of rows and columns, and can be thought of as a table or grid. Each element in the array is referenced by its position in the row and column.

How does Fortran 90 store multidimensional arrays in memory?

Fortran 90 stores multidimensional arrays in a column-major order, also known as a "column-wise" storage layout. This means that the elements of each column are stored contiguously in memory, followed by the elements of the next column, and so on. This is in contrast to a row-major order, where the elements of each row would be stored contiguously.

Can the dimensions of a multidimensional array in Fortran 90 be changed?

No, the dimensions of a multidimensional array in Fortran 90 are fixed and cannot be changed once the array has been declared. If a different size is needed, a new array with the desired dimensions must be declared and the data from the original array must be copied over.

How do you access individual elements of a multidimensional array in Fortran 90?

To access an individual element of a multidimensional array in Fortran 90, you must specify the row and column indices for the element you want to access. For example, to access the element in the second row and third column, you would use the syntax "array(2,3)".

Can a multidimensional array in Fortran 90 have more than two dimensions?

Yes, a multidimensional array in Fortran 90 can have any number of dimensions, as long as it is declared with the correct number of dimensions. However, arrays with more than three dimensions are not commonly used and can be difficult to work with.

Similar threads

  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
6
Views
977
  • Programming and Computer Science
Replies
21
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
19
Views
5K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
Back
Top