Sun f90 bad optimization for assumed-shape array

From: Bastiaan Braams (braams_at_courant.nyu.edu)
Date: 07/23/04


Date: 23 Jul 2004 07:44:52 -0700

In profiling my code I noticed strange behavior on a Sun system.
I am on an Ultra-III machine and this is the Fortran compiler:

f90: Forte Developer 7 Fortran 95 7.0 Patch 111714-09 2003/10/15

I compile with use of the "-fast" option.

A critical routine in my code has a heading similiar to this:

| subroutine foo (n, x, w)
| integer, intent (in) :: n
| real (kind=dp), intent (in) :: x(0:)
| real (kind=dp), intent (out) :: w(0:)

The expected size of w is n, and at the top of my code I test

| if (size(w).ne.n) then
| stop '...'
| endif

Profiling tells me that this subroutine executes three times faster
if the declaration of w is replaced by

| real (kind=dp), intent (out) :: w(0:n-1)

Is this kind of behavior a known feature? I'm quite annoyed with
it, because the replacement declaration is much more sensitive to
errors. (A routine that calls foo could pass to w an array of any
size at least w and of any dimension, and all is legal.)

Bas Braams