C version code works. The corresponding Fortran version is blocked by the compiler errror. C version: #include <stdio.h> int main() { int a[1]; int* b = a; a[0] = 0; #pragma omp target enter data map(to:b[:1]) #pragma omp target data use_device_ptr(b) { #pragma omp target is_device_ptr(b) { b[0] = 1; } } printf("value before exit data %d\n", b[0]); #pragma omp target exit data map(from:b[:1]) printf("value after exit data %d\n", b[0]); return 0; } Fortran version, XL fortran compiler works with this case. program abc implicit none integer a a = 0 call test(a) contains subroutine test(a) implicit none integer a !$omp target enter data map(to:a) !$omp target data use_device_ptr(a) ! Error: TARGET DATA must contain at least one MAP clause at (1) ! after adding map(to: a), the second printout is still wrong. !$omp target is_device_ptr(a) a = 1 !$omp end target !$omp end target data write(6,*) "before exit data a = ", a !$omp target exit data map(from:a) write(6,*) "after exit data a = ", a endsubroutine end program
The error is correct for OpenMP 4.5, !$omp target data there has the restriction: At least one map clause must appear on the directive. and OpenMP 4.5 is what GCC 10 implements in Fortran mostly. OpenMP 5.0 and 5.1 changes that restriction to: At least one map, use_device_addr or use_device_ptr clause must appear on the directive. which is what you can see in the C and C++ FEs. GCC 11 is going to implement the 5.0 behavior here even in Fortran.
@jakub thanks for the quick reply. However, even if I add map(to: a) which is almost a no-op to satisfy the compiler for 4.5 spec. The printout result is still wrong. It should be 0 and 1 but the fortran case prints 0 and 0.
I verified that current master has removed the syntax restriction. However, the printout remains incorrect.
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563784.html
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>: https://gcc.gnu.org/g:049bfd186fae9fb764a3ec04acb20d3eaacda7a3 commit r11-6787-g049bfd186fae9fb764a3ec04acb20d3eaacda7a3 Author: Tobias Burnus <tobias@codesourcery.com> Date: Tue Jan 19 11:57:34 2021 +0100 OpenMP/Fortran: Fixes for {use,is}_device_ptr gcc/fortran/ChangeLog: PR fortran/98476 * openmp.c (resolve_omp_clauses): Change use_device_ptr to use_device_addr for unless type(c_ptr); check all list item for is_device_ptr. gcc/ChangeLog: PR fortran/98476 * omp-low.c (lower_omp_target): Handle nonpointer is_device_ptr. libgomp/ChangeLog: PR fortran/98476 * testsuite/libgomp.fortran/is_device_ptr-1.f90: New test. gcc/testsuite/ChangeLog: PR fortran/98476 * gfortran.dg/gomp/map-3.f90: Update expected scan-dump-tree. * gfortran.dg/gomp/is_device_ptr-2.f90: New test. * gfortran.dg/gomp/use_device_ptr-1.f90: New test.
Close as FIXED. Thanks for the report, especially for checking already upcoming GCC 11, which helps to iron out issues before the release :-)
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>: https://gcc.gnu.org/g:c05cdfb3f6335d55226cef7917a783498aa41244 commit r11-6809-gc05cdfb3f6335d55226cef7917a783498aa41244 Author: Tobias Burnus <tobias@codesourcery.com> Date: Wed Jan 20 08:31:30 2021 +0100 OpenMP/Fortran: Fix gfortran.dg/gomp/is_device_ptr-2.f90 gcc/testsuite/ChangeLog: PR fortran/98757 PR fortran/98476 * gfortran.dg/gomp/is_device_ptr-2.f90: Fix dg-error.