From patchwork Fri Jun 3 13:37:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 54780 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89155381E4F8 for ; Fri, 3 Jun 2022 13:38:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 9390D38515D1; Fri, 3 Jun 2022 13:38:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9390D38515D1 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.91,274,1647331200"; d="diff'?scan'208";a="76638216" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 03 Jun 2022 05:38:20 -0800 IronPort-SDR: Jz8DepMBtIdQa08hAXa1eps6cXOTDk03tFUKCoC+yt3TUonqq+byC7331637f1l+xh9RUBrvJ+ 5ZKNrnR5f8tD5jKdz+DTH3crYpIQKF/nxndsLgpMcac2OJmStVuroJofxqWp/AS31w9c1GlCrH 4HPXlKuzd63dqwlYraUAs/7vvRunw75XkfwMhfBWZvSpRVaukw4GIjFRs+ePwkHExFmdOsmAwJ Oz23J9K2Gye3ubpfGAG7VhVk4ndCYBHF6HJ+8ao2zmKjDwt0CGRRrWN+2Rf+n5E0Q8x+sBmAKw kZM= Message-ID: Date: Fri, 3 Jun 2022 15:37:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP/Fortran: Add support for firstprivate and allocate clauses on scope construct X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Simple patch. Testcases based on the C/C++ commit. For allocate, I found an unrelated bug which prevented me from adding the associated testcase: https://gcc.gnu.org/PR105836 Tested on x86-64 (w/o offloading). OK for mainline? Tobias ----------------- 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 OpenMP/Fortran: Add support for firstprivate and allocate clauses on scope construct Fortran commit to C/C++/backend commit r13-862-gf38b20d68fade5a922b9f68c4c3841e653d1b83c gcc/fortran/ChangeLog: * openmp.cc (OMP_SCOPE_CLAUSES): Add firstprivate and allocate. libgomp/ChangeLog: * libgomp.texi (OpenMP 5.2): Mark scope w/ firstprivate/allocate as Y. * testsuite/libgomp.fortran/scope-2.f90: New test. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/scope-5.f90: New test. * gfortran.dg/gomp/scope-6.f90: New test. gcc/fortran/openmp.cc | 3 +- gcc/testsuite/gfortran.dg/gomp/scope-5.f90 | 9 +++++ gcc/testsuite/gfortran.dg/gomp/scope-6.f90 | 23 +++++++++++ libgomp/libgomp.texi | 2 +- libgomp/testsuite/libgomp.fortran/scope-2.f90 | 57 +++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index a1aa88c5d74..d12cec43d64 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -3682,7 +3682,8 @@ cleanup: | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_REDUCTION) #define OMP_SCOPE_CLAUSES \ - (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_REDUCTION) + (omp_mask (OMP_CLAUSE_PRIVATE) |OMP_CLAUSE_FIRSTPRIVATE \ + | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_ALLOCATE) #define OMP_SECTIONS_CLAUSES \ (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE \ | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_ALLOCATE) diff --git a/gcc/testsuite/gfortran.dg/gomp/scope-5.f90 b/gcc/testsuite/gfortran.dg/gomp/scope-5.f90 new file mode 100644 index 00000000000..baddae51b42 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/scope-5.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } + +subroutine foo () + integer f + f = 0; + !$omp scope firstprivate(f) ! { dg-error "firstprivate variable 'f' is private in outer context" } + f = f + 1 + !$omp end scope +end diff --git a/gcc/testsuite/gfortran.dg/gomp/scope-6.f90 b/gcc/testsuite/gfortran.dg/gomp/scope-6.f90 new file mode 100644 index 00000000000..9c595b1e117 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/scope-6.f90 @@ -0,0 +1,23 @@ +! { dg-additional-options "-fdump-tree-original" } + +module m + use iso_c_binding + !use omp_lib, only: omp_allocator_handle_kind + implicit none + integer, parameter :: omp_allocator_handle_kind = c_intptr_t + integer :: a = 0, b = 42, c = 0 + +contains + subroutine foo (h) + integer(omp_allocator_handle_kind), value :: h + !$omp scope private (a) firstprivate (b) reduction (+: c) allocate ( h : a , b , c) + if (b /= 42) & + error stop + a = 36 + b = 15 + c = c + 1 + !$omp end scope + end +end + +! { dg-final { scan-tree-dump "omp scope private\\(a\\) firstprivate\\(b\\) reduction\\(\\+:c\\) allocate\\(allocator\\(D\\.\[0-9\]+\\):a) allocate\\(allocator\\(D\\.\[0-9\]+\\):b) allocate\\(allocator\\(D\\.\[0-9\]+\\):c)" "original" } } diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index ff02ccd4969..11613bf7599 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -386,7 +386,7 @@ The OpenMP 4.5 specification is fully supported. @item Deprecation of delimited form of @code{declare target} @tab N @tab @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab @item @code{allocate} and @code{firstprivate} clauses on @code{scope} - @tab N @tab + @tab Y @tab @item @code{ompt_callback_work} @tab N @tab @item Default map-type for @code{map} clause in @code{target enter/exit data} @tab N @tab diff --git a/libgomp/testsuite/libgomp.fortran/scope-2.f90 b/libgomp/testsuite/libgomp.fortran/scope-2.f90 new file mode 100644 index 00000000000..f2e1593403e --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/scope-2.f90 @@ -0,0 +1,57 @@ +program main + implicit none + integer a(0:63) + integer r, r2, i, n + a = 0 + r = 0 + r2 = 0 + n = 64 + !$omp parallel + !$omp scope + !$omp scope firstprivate (n) + !$omp do + do i = 0, 63 + a(i) = a(i) + 1 + end do + !$omp end scope nowait + !$omp end scope nowait + + !$omp scope reduction(+: r) firstprivate (n) + !$omp do + do i = 0, 63 + r = r + i + if (a(i) /= 1) & + error stop + end do + !$omp end do nowait + !$omp barrier + if (n /= 64) then + error stop + else + n = 128 + end if + !$omp end scope nowait + + !$omp barrier + if (r /= 64 * 63 / 2) & + error stop + !$omp scope private (i) + !$omp scope reduction(+: r2) + !$omp do + do i = 0, 63 + r2 = r2 + 2 * i + a(i) = a(i) + i + end do + !$omp end do nowait + !$omp end scope + !$omp end scope nowait + if (r2 /= 64 * 63) & + error stop + !$omp do + do i = 0, 63 + if (a(i) /= i + 1) & + error stop + end do + !$omp end do nowait + !$omp end parallel +end program