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 via email to