Alignment of gfortran allocated arrays

François-Xavier Coudert fxcoudert@gmail.com
Tue Aug 14 16:59:00 GMT 2007


Hi John,

> Anyway, I'm trying to ensure that arrays I allocate in gfortran are 16
> byte aligned for use with
> fftw  < http://www.fftw.org/>. I notice that this issue was previously
> discussed on this list:
>
> http://gcc.gnu.org/ml/fortran/2007-05/msg00494.html
>
> and the blame for sorting this out placed on libc malloc (via the bug report at:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24261
>
> Has anything changed since this discussion?

No, not that I know of at least.

> It didn't sound like the libc guys were going to
> change the default malloc behaviour. Has a compile switch been added
> to ask for this or
> perhaps an extension to gfortran to use one of the alternatives to
> malloc which allows
> alignment (posix_memalign or memalign)? If not, could one possibly be
> added (I'll even try and
> make up a patch, though I know nothing of gfortran internals and so it
> may take me a while).

Nothing has been done. To consider a possible compiler switch, we
would need at least the following (in my opinion):

  * how do other compilers solve the problem?
  * what kind of allocations
  * how portable is the memory allocation scheme you suggest
(memalign, posix_memalign, etc.)?
  *

Now, if you were to work on a patch for inclusion of a switch for
controlled-alignment of allocated memory, you would need to:
  1. add the option itself: what name, what possible values, for which targets?
  2. add support for front-end emitted malloc calls (there are emitted
by a unique function: gfc_call_malloc)
  3. add support to the library routines in libgfortran/runtime/memory.c
  4. last: add a way for the front-end to communicate the desired
alignment to the library (to include in set_options, generated from
the front-end function gfc_generate_function_code)


This is not difficult, but not trivial either and has to be thought
through carefully. Furthermore, it will need reviewing and
maintaining, which has to be weighted against the use it will have.

Thanks,
FX



More information about the Fortran mailing list