This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, fortran] Add -frecursive and fix local array handling with -fopenmp


Hi Janne, Hi Asher, hi all,

Janne Blomqvist wrote:
> On 8/15/07, Asher Langton <langton2@llnl.gov> wrote:
>   
>> I also added an '-frecursive' flag, which sets max_stack_var_size to -1.
> For a slightly modified approach, why not leave the -frecursive option
> part of the patch out as unnecessary [...], and make
> flag_max_stack_var_size=-1 the default
> rather than the current (arbitrary?) limit of 32768. Those who then
> really want some cutoff size to store local variable statically can
> then use the -fmax-stack-var-size= option explicitly rather than start
> seeing weird effects for when going over the limit like Asher did when
> using OpenMP (I guess it's not very obvious why things start to fail
> in this case).

ifort has the options:
-auto-scalar (default): put scalars to the stack
-save: put variables in static memory (except in recursively declared
procedures)
-auto/-automatic: Puts all local, non-SAVE variables on the stack
-openmp/-recursive: Implies -auto/-automatic

gfortran (currently):
-fno-automatic: As Intel's -save: use static memory
-fmax-stack-var-size=<n> stack vs. static memory; incl. n=-1 to put all
on the stack

Actually, the gfortran man page (invoke.texi) is a bit unclear. I
therefore suggest the attach patch (which is independent of Asher's patch).

As stack overflows are hard to debug, I am in favour of keeping
-fmax-stack-var-size=n with n > 0.
(Which in a way even Intel does - though using -auto-scalar their limit
is even lower.)

Note that you only see "weird things" if you have either parallel code
(-fopenmp) which is fixed by Asher's patch or whether you are using
recurse code without specifying RESCURSIVE, which is invalid Fortran.


Regarding Asher's patch, I think it is OK as it.


> And, since running out of stack space due to large arrays on the stack
> seems to be much more common in Fortran rather than recursing
> infinitely, add something like the following to
> libgfortran/runtime/main.c:
>   
I'm not sure whether the users like a program tinker with the ulimit
(soft) limits. I have also to admit that I did not see yet reports of
stack-overflow crashes using gfortran; as ifort uses the stack also for
automatic arrays (gfortran always uses the heap), I saw several reports
for ifort and was bitten by it more than once. If gfortran had
-fmax-stack-var-size=-1 by default, I'm sure we would see more of such
reports as g77 programs often had rather large local arrays.

Taken into account hard limits and that the needed stack size depends on
the program, I think having reasonable error/warning messages is
impossible and except of "unlimited" (which is not always wanted) or the
hard limit (which might be still to low) one has no choice in
runtime/main.c. I would therefore suggest to keep the status quo.

Tobias

PS: A rather nice overview about static vs. heap vs. stack can be found at:
http://softwarecommunity.intel.com/isn/Community/en-US/forums/post/116178.aspx

Index: invoke.texi
===================================================================
--- invoke.texi (Revision 127532)
+++ invoke.texi (Arbeitskopie)
@@ -710,10 +710,12 @@
 @opindex @code{fno-automatic}
 @cindex @code{SAVE} statement
 @cindex statement, @code{SAVE}
-Treat each program unit as if the @code{SAVE} statement was specified for
-every local variable and array referenced in it. Does not affect common
-blocks. (Some Fortran compilers provide this option under the name
-@option{-static}.)
+Treat each program unit (except those marked as RECURSIVE) as if the
+@code{SAVE} statement was specified for every local variable and array
+referenced in it. Does not affect common blocks. (Some Fortran compilers
+provide this option under the name @option{-static} or @option{-save}.)
+The default is @option{-fautomatic} which uses the stack for local
+variables smaller than the value given by @option{-fmax-stack-var-size}.

 @item -ff2c
 @opindex ff2c
@@ -865,7 +867,8 @@
 @item -fmax-stack-var-size=@var{n}
 @opindex @code{fmax-stack-var-size}
 This option specifies the size in bytes of the largest array that will be put
-on the stack.
+on the stack; if the size is exceeded static memory is used (except in
+procedures marked as RECURSIVE). If @var{n}=-1 the stack is always used.

 This option currently only affects local arrays declared with constant
 bounds, and may not apply to all character variables.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]