From: Tobias Burnus <tobias@codesourcery.com>
To: Tobias Melson <tobias.melson@mpcdf.mpg.de>
Cc: fortran <fortran@gcc.gnu.org>
Subject: Re: Alignment of arrays
Date: Wed, 21 Dec 2022 10:26:09 +0100 [thread overview]
Message-ID: <b530a341-74e9-2f53-2b45-4a89771f4a78@codesourcery.com> (raw)
In-Reply-To: <429718a5-5f63-5bd2-7416-69690a334f8a@mpcdf.mpg.de>
Dear Tobias, hi all,
On 21.12.22 09:40, Tobias Melson via Fortran wrote:
> I am wondering about alignment of allocatable arrays: Does the
> gfortran compiler in its latest version automatically align arrays to
> the 64 byte boundary? For comparison, the Intel compiler has a flag
> "-align array64byte", which forces alignment of all arrays (except for
> the ones in COMMON). I did not find something similar in the gfortran
> documentation.
I concur that this feature is useful. But I think that's currently not
possible.
Workaround: Do the allocation with C. The more invasive method is with
pointers and the 'call c_f_pointer'. The more flexible method, using
allocatables (or pointers) is to use the C descriptor on the C side
(CFI_allocate etc.) – for the latter GCC 12 (or later) is recommended as
there were several bugfixes.
(Side remark: "!$omp allocators allocate(align(64) : foobar);
allocate(foobar...)" or (deprecated) "!$omp allocate(foobar) align(64);
allocate(foobar...)" would do something like that – but that's not yet
implemented in GCC/gfortran. [Support is planned, but will take a while,
only parsing-only support is nearly ready.].)
> Best regards from Munich
> Tobias
Best regards – usually but not currently also from Munich,
Tobias
PS: Regarding the C array descriptor, I mean something like, which is
GCC specific as other compilers might do more complex things inside
CFI_allocate – GCC only does:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgfortran/runtime/ISO_Fortran_binding.c#l212
and calls a normal 'free' on deallocate.
#include <ISO_Fortran_binding.h>
#include <stdlib.h>
void my_allocate_rank1 (CFI_cdesc_t *dv, const size_t lower_bounds[],
const size_t upper_bounds[], size_t alignment)
{
// Using 'dv->elem_len' assumes no 'character(len=:)' as type, cf. CFI_allocate
// in the ISO Fortran standard and in libgfortran's implementation
size_t sz = upper_bounds[0] < lower_bounds[0] ? 0
: upper_bounds[0} - lower_bounds[0] + 1;
posix_memalign (&dv->base_addr, alignment, dv->elem_len * sz);
dv->dim[0].extend = sz;
dv->dim[0].lower_bound = lower_bounds[0];
dv->dim[0].sm = elem_len;
}
And something like the following (unfortunately 'type(*)' is not permitted
with allocatable, hence 'real' is used):
interface
subroutine my_allocate_rank1 (x, lower_bounds, upper_bounds, alignment) bind(C)
use iso_c_binding
real, allocatable :: x(:)
! intent(out) :: x ! to auto-deallocate
integer(c_size_t) :: lower_bounds(1), upper_bounds(1)
integer(c_size_t), value :: alignment
end
end interface
real, allocatable :: var(:)
call my_allocate_rank1 (var, [1], [N], 64)
end
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
prev parent reply other threads:[~2022-12-21 9:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-21 8:40 Tobias Melson
2022-12-21 9:26 ` Tobias Burnus [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b530a341-74e9-2f53-2b45-4a89771f4a78@codesourcery.com \
--to=tobias@codesourcery.com \
--cc=fortran@gcc.gnu.org \
--cc=tobias.melson@mpcdf.mpg.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).