fmax-stack-var-size, was: Re: OpenMP and local arrays

Asher Langton langton2@llnl.gov
Fri Aug 3 16:48:00 GMT 2007


On 8/2/07, Steve Kargl <sgk@troutmask.apl.washington.edu> wrote:
> On Wed, Aug 01, 2007 at 11:39:29AM -0700, Asher Langton wrote:
> > On 7/31/07, Asher Langton <langton2@llnl.gov> wrote:
> > >
> > > Here's a strange problem involving OpenMP and local arrays that are
> > > treated as static:
> > >
> > > program rd
> > >   implicit none
> > >   integer id
> > >   integer omp_get_thread_num
> > > !$omp parallel private (id)
> > >   id = omp_get_thread_num()
> > >   call foo (id)
> > > !$omp end parallel
> > > end program rd
> > >
> > > subroutine foo (id)
> > >   implicit none
> > >   integer id
> > >   real x(100,100)
> > >   print *,"thread",id,"loc(x)",loc(x)
> > > end subroutine foo
> > >
> > >
> > > Using 'ifort -openmp' or 'pgf90 -mp', each thread has its own copy of
> > > the array x.  However, with 'gfortran -fopenmp', all of the threads
> > > are competing for the same copy of x.  It appears that ifort's
> > > '-openmp' implies '-auto', and pgf90's '-mp' invokes an internal flag
> > > called '-nostatic' (equivalent to '-Mrecursive', I think).
> > >
> > > I couldn't find a comparable flag in gfortran to invoke with
> > > '-fopenmp'.  The '-fautomatic' flag (which is on by default) is not
> > > the same as ifort's '-auto', is it?  It seems to just be the opposite
> > > of '-fno-automatic', but doesn't necessarily make all locally-scoped
> > > variables automatic.  Is there any flag that can be set automatically
> > > by -fopenmp to force local variables to be automatic?
> >
> > To follow up on this: Mike Kumbera pointed out the
> > '-fmax-stack-var-size=' option.  What do you all think about adding a
> > flag that sets gfc_option.flag_max_stack_var_size to -1?  This should
> > be equivalent to ifort's '-auto' and pgf90's '-Mrecursive' options
> > (see trans-decl.c:gfc_can_put_var_on_stack () ).  Then '-fopenmp'
> > would also set  gfc_option.flag_max_stack_var_size to -1, and -- if
> > there's a demand for it -- we could add a '-frecursive' option that
> > does the same thing, which will allow indirect recursion to work
> > properly.
> >
>
> Given your program above and some testing I did locally, I think
> the above suggestion with -fmax-stack-var-size seems reasonable.
> I have no preference about a -frecursive option, but I also
> haven't given it much thought.

The max-stack-var-size fix solves some problems we've seen when
compiling our codes with OpenMP.  I'll put together a proper patch
today.  I think there ought be some way to set this directly, but
maybe it'll be enough just to make '-1' a valid argument to
'-fmax-stack-var-size' and document this.

-Asher



More information about the Fortran mailing list