public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, fortran] Add -frecursive and fix local array handling with -fopenmp
@ 2007-08-15 19:58 Asher Langton
  2007-08-15 21:53 ` Janne Blomqvist
  0 siblings, 1 reply; 9+ messages in thread
From: Asher Langton @ 2007-08-15 19:58 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

Hi all,

Here's a patch to fix the OpenMP issue with local arrays being
allocated statically, as discussed here:

http://gcc.gnu.org/ml/fortran/2007-08/msg00000.html

I also added an '-frecursive' flag, which sets max_stack_var_size to -1.


-Asher


:ADDPATCH fortran:

2007-08-15  Asher Langton  <langton2@llnl.gov>

        * gfortran.h (gfc_option_t): Add flag_recursive.
	* lang.opt: Add -frecursive option and update -fopenmp.
	* invoke.texi: Document new option.
	* options.c (gfc_init_options, gfc_post_options,
	gfc_handle_option): Add -frecursive and modify -fopenmp.

2007-08-15  Asher Langton  <langton2@llnl.gov>

	* gfortran.dg/recursive_stack.f90: New.
	* gfortran.dg/openmp_stack.f90: New.

[-- Attachment #2: gfc070815_125412.diff --]
[-- Type: application/octet-stream, Size: 3626 bytes --]

Index: gfortran.h
===================================================================
--- gfortran.h	(revision 127522)
+++ gfortran.h	(working copy)
@@ -1867,6 +1867,7 @@ typedef struct
   int flag_openmp;
   int flag_sign_zero;
   int flag_module_private;
+  int flag_recursive;
 
   int fpe;
 
Index: lang.opt
===================================================================
--- lang.opt	(revision 127522)
+++ lang.opt	(working copy)
@@ -218,7 +218,7 @@ Set default accessibility of module enti
 
 fopenmp
 Fortran
-Enable OpenMP
+Enable OpenMP (sets fmax-stack-var-size to be unlimited)
 
 fpack-derived
 Fortran
@@ -240,6 +240,10 @@ frecord-marker=8
 Fortran RejectNegative
 Use an 8-byte record marker for unformatted files
 
+frecursive
+Fortran
+Allocate local variables on the stack to allow indirect recursion
+
 frepack-arrays
 Fortran
 Copy array sections into a contiguous block on procedure entry
Index: invoke.texi
===================================================================
--- invoke.texi	(revision 127522)
+++ invoke.texi	(working copy)
@@ -156,7 +156,7 @@ and warnings}.
 -fsecond-underscore @gol
 -fbounds-check  -fmax-stack-var-size=@var{n} @gol
 -fpack-derived  -frepack-arrays  -fshort-enums  -fexternal-blas @gol
--fblas-matmul-limit=@var{n}}
+-fblas-matmul-limit=@var{n}} -frecursive
 @end table
 
 @menu
@@ -296,7 +296,8 @@ and @code{c$omp}, @code{*$omp} and @code
 @code{!$} conditional compilation sentinels in free form
 and @code{c$}, @code{*$} and @code{!$} sentinels in fixed form, 
 and when linking arranges for the OpenMP runtime library to be linked
-in.
+in.  The @option{-fopenmp} flag will override any setting of
+@option{-fmax-stack-var-size=}.
 
 @item -frange-check
 @opindex @code{frange-check}
@@ -865,7 +866,8 @@ substring references.
 @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.  The @option{-fopenmp} and @option{-frecursive} flags
+can override this setting.
 
 This option currently only affects local arrays declared with constant
 bounds, and may not apply to all character variables.
@@ -919,6 +921,12 @@ geometric mean of the dimensions of the 
 
 The default value for @var{n} is 30.
 
+@item -frecursive
+@opindex @code{frecursive}
+Allow indirect recursion by forcing all local arrays to be allocated
+on the stack.  This flag will override any value set with
+@option{fmax-stack-var-size=}.
+
 @end table
 
 @xref{Code Gen Options,,Options for Code Generation Conventions,
Index: options.c
===================================================================
--- options.c	(revision 127522)
+++ options.c	(working copy)
@@ -103,6 +103,7 @@ gfc_init_options (unsigned int argc ATTR
   gfc_option.flag_d_lines = -1;
   gfc_option.flag_openmp = 0;
   gfc_option.flag_sign_zero = 1;
+  gfc_option.flag_recursive = 0;
 
   gfc_option.fpe = 0;
 
@@ -294,6 +295,11 @@ gfc_post_options (const char **pfilename
   if (!gfc_option.flag_automatic)
     gfc_option.flag_max_stack_var_size = 0;
   
+  /* For OpenMP and indirect recusion, force local variables to
+     be allocated on the stack.  */
+  if (gfc_option.flag_openmp || gfc_option.flag_recursive)
+    gfc_option.flag_max_stack_var_size = -1;
+
   if (pedantic)
     { 
       gfc_option.warn_ampersand = 1;
@@ -698,6 +704,12 @@ gfc_handle_option (size_t scode, const c
 			 MAX_SUBRECORD_LENGTH);
 
       gfc_option.max_subrecord_length = value;
+      break;
+
+    case OPT_frecursive:
+      gfc_option.flag_recursive = 1;
+      break;
+
     }
 
   return result;

[-- Attachment #3: openmp_stack.f90 --]
[-- Type: application/octet-stream, Size: 520 bytes --]

! { dg-do run}
! { dg-options "-fopenmp" }
program openmp_stack
  implicit none
  integer id
  integer ilocs(2)
  integer omp_get_thread_num, foo
  call omp_set_num_threads (2)
!$omp parallel private (id)
  id = omp_get_thread_num() + 1
  ilocs(id) = foo()
!$omp end parallel
  ! Check that the two threads are not sharing a location for
  ! the array x in foo()
  if (ilocs(1) .eq. ilocs(2)) call abort
end program openmp_stack

integer function foo ()
  implicit none
  real x(100,100)
  foo = loc(x)
end function foo

[-- Attachment #4: recursive_stack.f90 --]
[-- Type: application/octet-stream, Size: 404 bytes --]

! { dg-do run}
! { dg-options "-frecursive" }
program recursive_stack
  call foo (.true.)
end program recursive_stack

subroutine foo (recurse)
  logical recurse
  integer iarray(100,100)
  if (recurse) then
     iarray(49,49) = 17
     call bar
     if (iarray(49,49) .ne. 17) call abort
  else
     iarray(49,49) = 21
  end if
end subroutine foo

subroutine bar
  call foo (.false.)
end subroutine bar

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-08-17 18:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-15 19:58 [PATCH, fortran] Add -frecursive and fix local array handling with -fopenmp Asher Langton
2007-08-15 21:53 ` Janne Blomqvist
2007-08-16  8:51   ` Tobias Burnus
2007-08-16  9:07     ` Jakub Jelinek
2007-08-16 18:34       ` Asher Langton
2007-08-16 18:24     ` Asher Langton
2007-08-17  7:53       ` Tobias Burnus
2007-08-17 18:34         ` Asher Langton
2007-08-16 11:48   ` François-Xavier Coudert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).