Clicky

Fortran Wiki
Assumed shape array discussion

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

What are the performance considerations of assumed shape arrays?

Examples of the two primary alternatives:

! This is a subroutine using assumed shape array
subroutine test_as(array)
 real, intent(in), dimension(:) :: array
 ! ...
end subroutine test_as
! This is a subroutine using automatic arrays
subroutine test_auto(array, n)
 real, intent(in), dimension(n) :: array
 integer, intent(in) :: n
 ! ...
end subroutine test_auto

One of the major differences is that an assumed-shape array can be "strided". If you pass an array section, such as the third column in a 2D array, the caller can pass an array reference that points to strided (non-contiguous) data in memory. That can be an advantage, because the source array does not have to be packed into a contiguous temporary array. However, when the routine is called with contiguous arrays, the optimization can be hindered.

Another difference, especially for multi-dimensional arrays. is that a small, fixed inner dimension can be optimized more efficiently. If a coordinate array always has dimension (3,*), there is no need to implement a loop over the 3 inner elements. If declared (:,:), there is a good chance that a loop will be used.

Revised on July 1, 2010 13:15:31 by Joe Krahn (157.98.68.58) (2523 characters / 1.0 pages)
Edit | Back in time (4 revisions) | See changes | History | Views: Print | TeX | Source | Linked from: Discussion

AltStyle によって変換されたページ (->オリジナル) /