From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 67BB33858439 for ; Wed, 21 Dec 2022 09:26:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 67BB33858439 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.96,262,1665475200"; d="scan'208";a="93743891" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 21 Dec 2022 01:26:14 -0800 IronPort-SDR: SP/DKUdxV3yKAG64p2Rx95UIVuTa388CislhnIapeC/LsHbWxtVHqajFc3nZbb0v+6oQa8ugkq 7FpalfKbqqukLtu11hrMrKcCZah5ghMltKDDQOhWuwSlMSA/C46YV9w1wmjqx+bnvOQ7W55i21 8wezNZ1NGR2xCktYOfMleyYvLWUCfft5Jv0HzAqwtzt7KhkaPpKFtxffmkmRrk0n2w6REUWVIt JKeB+8Hi2bA6IlQCGVaSx/vZ9CAkw4Rl5eGMUvvpCoYMcyuSBVn1qJP0vrqIlIwxwBDim4YNXf Dl0= Message-ID: Date: Wed, 21 Dec 2022 10:26:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: Alignment of arrays Content-Language: en-US To: Tobias Melson References: <429718a5-5f63-5bd2-7416-69690a334f8a@mpcdf.mpg.de> From: Tobias Burnus CC: fortran In-Reply-To: <429718a5-5f63-5bd2-7416-69690a334f8a@mpcdf.mpg.de> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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.) =E2=80=93 for the latter GCC 12 (or later) is recommend= ed 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 =E2=80=93 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 =E2=80=93 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 =E2=80=93 GCC only does: https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dblob;f=3Dlibgfortran/runtime/ISO_F= ortran_binding.c#l212 and calls a normal 'free' on deallocate. #include #include 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=3D:)' as type, cf. CFI_al= locate // in the ISO Fortran standard and in libgfortran's implementation size_t sz =3D 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 =3D sz; dv->dim[0].lower_bound =3D lower_bounds[0]; dv->dim[0].sm =3D 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=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955