public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <burnus@net-b.de>
To: Jakub Jelinek <jakub@redhat.com>,
	gcc-patches@gcc.gnu.org,  fortran@gcc.gnu.org
Subject: Re: [PATCH] Fortran OpenMP 4.0 support, part 1
Date: Fri, 09 May 2014 19:35:00 -0000	[thread overview]
Message-ID: <536D2DE7.8060701@net-b.de> (raw)
In-Reply-To: <20140507205303.GF10386@tucnak.redhat.com>

Hi!

Jakub Jelinek wrote:
> This patch attempts to implement first part of Fortran OpenMP 4.0 support,
> The testsuite coverage could certainly be improved, volunteers for that
> and/or bugreports will be certainly appreciated.  Don't know how to actually
> test aligned clauses, is there any way (except for doing allocations in
> C/C++ on the side) to allocate objects on aligned boundaries (aligned
> attribute, some way to dynamically allocate aligned storage, ...)?

Fortran - as also C and C++ - does not provide much support for aligned 
memory. [Well, C++ has now alignas and align(ment_)of.] But contrary to 
C/C++, using library functions for dynamic allocation is more difficult 
and gfortran doesn't support GCC's align attribute for non-heap 
allocation. I only know of one commercial compiler, which has alignment 
directives (for static and dynamically allocated memory). I also was 
considering adding support for it - but I haven't found the time to do 
so, yet.

Thus, you can either do the allocation in C/C++, call the C function 
directly (but requires a manually written interface), or manually align 
the memory - e.g. by checking the address and adding an offset.

Actually, the latter might be the simplest: Allocate - statically or 
dynamically - the memory somewhere - and calculate the offset. For instance:


   use iso_c_binding
   implicit none

   integer :: array(1024), y ! Or dynamically allocated
   integer(c_ptrdiff_t) :: offset, byte_size
   integer, parameter :: ALIGNVALUE = 128

   offset = ALIGNVALUE - mod (loc (array), ALIGNVALUE)
   if (offset == ALIGNVALUE) &
     offset = 0
   offset = offset/c_sizeof(y)

   call some_subroutine(array(1+offset:))
contains
   subroutine some_subroutine(x)
     integer :: x(:)
     if (mod (loc(x), ALIGNVALUE) /= 0) &
       call abort()
   end subroutine some_subroutine
end

(Side remark: The code uses "loc()" which is a vendor extension; C_LOC() 
can also be used, but that requires the target or pointer attribute.)


> Bootstrapped/regtested on x86_64-linux and i686-linux.  Any comments on
> this?

Looks good to me - not that I checked every line. One small nit below.


>   +/* For use in OpenMP clauses in case we need extra information
> +   (aligned clause alignment, linear clause step, etc.  */

The ")" is missing in the comment.

  * * *

BTW: I think it would be nice to have a better error message for the 
following:

! ---------------------------------------
integer :: a(10) = [1,2,3,4,5,6,7,8,9,0]
integer :: i

!$omp simd safelen(i) linear(a:2) safelen(i)
do i = 1, 5
end do
end
! ---------------------------------------

It currently fails with:
   Error: Unclassifiable OpenMP directive at (1)
but the only problem is that there are two "safelen".

With C, one gets a better message:
foo.c:6:25: error: too many 'safelen' clauses


Question is the following valid or not?

void test() {
int  a[10];
int i;
#pragma omp simd linear(a:2) safelen(i)
for (i = 1; i < 5; i++)
    ;
}

It is rejected with:
foo.c:5:24: error: linear clause applied to non-integral non-pointer 
variable with type 'int[10]'


Tobias

  reply	other threads:[~2014-05-09 19:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 20:53 Jakub Jelinek
2014-05-09 19:35 ` Tobias Burnus [this message]
2014-05-09 20:23   ` Jakub Jelinek
2014-05-10  6:16     ` Tobias Burnus
2014-05-10  8:32       ` Tobias Burnus

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=536D2DE7.8060701@net-b.de \
    --to=burnus@net-b.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /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).