From patchwork Mon Oct 8 17:58:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 980705 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487156-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OrUQCymS"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42TSm24CDmz9vZs for ; Tue, 9 Oct 2018 04:58:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=RTBonW0b3FIG9c2Upwv6y4qtmOjqS7Nr/ZiREU9KqAX AlX7tUd6C+dmplkwk1HQ7JgT0DRCRLq25KR2CEckQ4nM28BQVRpw39QI9hq5pLz5 2XdFfzM2QErom4V1GBPjbujzkeYsrrP5YyIvkiIkwBmp6jIliY8yH9DLm655SmsU = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=PCM8KBtyt3DJ5YqwEsc6B8uEdcg=; b=OrUQCymSFo9rMSIzx GFjrCPUMjrEKF+JfaWPjPpd7u12qjXpfGq+EK4aVq4CKrshLCqgTTscvcF20Hofy n2VsTx1dczQs2Z/FlB7+kQ3iJgURM812kW8dtpyHn50I7I9k620IxfTsQRkeHKSC 2A+DvS7wHbtQddabIN2vaDmH5s= Received: (qmail 108369 invoked by alias); 8 Oct 2018 17:58:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 108358 invoked by uid 89); 8 Oct 2018 17:58:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=170 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 Oct 2018 17:58:49 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2087CC0578F8 for ; Mon, 8 Oct 2018 17:58:48 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-82.ams2.redhat.com [10.36.116.82]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B924D5D77E for ; Mon, 8 Oct 2018 17:58:47 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w98HwiEI032419 for ; Mon, 8 Oct 2018 19:58:44 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w98HwhIA032418 for gcc-patches@gcc.gnu.org; Mon, 8 Oct 2018 19:58:43 +0200 Date: Mon, 8 Oct 2018 19:58:43 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [gomp5] Fix task reduction handling in implicit parallel regions Message-ID: <20181008175843.GK11625@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! In implicit parallel regions, we have NULL teams and often NULL task. For task reductions we need both non-NULL, so this patch creates such a team in that case, like we do already for target nowait. Tested on x86_64-linux, committed to gomp-5_0-branch. 2018-10-08 Jakub Jelinek * task.c (GOMP_taskgroup_reduction_register): If team is NULL, create implicit team with 1 thread and call GOMP_taskgroup_start again. Don't mix declarations with statements. * team.c (gomp_team_end): Determine nesting by thr->ts.level != 0 rather than thr->ts.team != NULL. * testsuite/libgomp.c-c++-common/task-reduction-4.c: New test. Jakub --- libgomp/task.c.jj 2018-10-08 12:20:53.712125100 +0200 +++ libgomp/task.c 2018-10-08 18:29:51.410292170 +0200 @@ -1968,11 +1968,45 @@ GOMP_taskgroup_reduction_register (uintp { struct gomp_thread *thr = gomp_thread (); struct gomp_team *team = thr->ts.team; - struct gomp_task *task = thr->task; - unsigned nthreads = team ? team->nthreads : 1; + struct gomp_task *task; + if (__builtin_expect (team == NULL, 0)) + { + /* The task reduction code needs a team and task, so for + orphaned taskgroups just create the implicit team. */ + struct gomp_task_icv *icv; + team = gomp_new_team (1); + task = thr->task; + icv = task ? &task->icv : &gomp_global_icv; + team->prev_ts = thr->ts; + thr->ts.team = team; + thr->ts.team_id = 0; + thr->ts.work_share = &team->work_shares[0]; + thr->ts.last_work_share = NULL; +#ifdef HAVE_SYNC_BUILTINS + thr->ts.single_count = 0; +#endif + thr->ts.static_trip = 0; + thr->task = &team->implicit_task[0]; + gomp_init_task (thr->task, NULL, icv); + if (task) + { + thr->task = task; + gomp_end_task (); + free (task); + thr->task = &team->implicit_task[0]; + } +#ifdef LIBGOMP_USE_PTHREADS + else + pthread_setspecific (gomp_thread_destructor, thr); +#endif + GOMP_taskgroup_start (); + } + unsigned nthreads = team->nthreads; size_t total_cnt = 0; - uintptr_t *d = data; - uintptr_t *old = task->taskgroup->reductions; + uintptr_t *d = data, *old; + struct htab *old_htab = NULL, *new_htab; + task = thr->task; + old = task->taskgroup->reductions; do { size_t sz = d[1] * nthreads; @@ -1992,13 +2026,12 @@ GOMP_taskgroup_reduction_register (uintp d = (uintptr_t *) d[4]; } while (1); - struct htab *old_htab = NULL; if (old && old[5]) { old_htab = (struct htab *) old[5]; total_cnt += htab_elements (old_htab); } - struct htab *new_htab = htab_create (total_cnt); + new_htab = htab_create (total_cnt); if (old_htab) { /* Copy old hash table, like in htab_expand. */ --- libgomp/team.c.jj 2018-07-27 12:57:16.000000000 +0200 +++ libgomp/team.c 2018-10-08 19:05:58.135130888 +0200 @@ -945,7 +945,7 @@ gomp_team_end (void) gomp_end_task (); thr->ts = team->prev_ts; - if (__builtin_expect (thr->ts.team != NULL, 0)) + if (__builtin_expect (thr->ts.level != 0, 0)) { #ifdef HAVE_SYNC_BUILTINS __sync_fetch_and_add (&gomp_managed_threads, 1L - team->nthreads); --- libgomp/testsuite/libgomp.c-c++-common/task-reduction-4.c.jj 2018-10-08 18:35:52.181268647 +0200 +++ libgomp/testsuite/libgomp.c-c++-common/task-reduction-4.c 2018-10-08 18:35:52.181268647 +0200 @@ -0,0 +1,70 @@ +extern +#ifdef __cplusplus +"C" +#endif +void abort (void); + +void +bar (long long int *p) +{ + p[0] *= 2; + #pragma omp task in_reduction (*: p[0]) + p[0] *= 3; +} + +void +foo (long long int *p, long long int *q) +{ + #pragma omp taskgroup task_reduction (*: p[0]) + { + #pragma omp task in_reduction (*: p[0]) + bar (p); + #pragma omp task in_reduction (*: p[0]) + bar (p); + bar (p); + #pragma omp taskgroup task_reduction (*: q[0]) + { + #pragma omp task in_reduction (*: q[0]) + bar (q); + #pragma omp task in_reduction (*: q[0]) + bar (q); + #pragma omp task in_reduction (*: q[0]) + bar (q); + bar (q); + #pragma omp task in_reduction (*: p[0]) + { + #pragma omp taskgroup task_reduction (*: p[0]) + { + #pragma omp task in_reduction (*: p[0]) + bar (p); + p[0] *= 2; + #pragma omp task in_reduction (*: p[0]) + bar (p); + } + } + } + } +} + +int +main () +{ + long long int p = 1LL, q = 1LL; + foo (&p, &q); + if (p != 6LL * 6LL * 6LL * 6LL * 6LL * 2LL || q != 6LL * 6LL * 6LL * 6LL) + abort (); + p = 1LL; + q = 1LL; + #pragma omp taskgroup + foo (&p, &q); + if (p != 6LL * 6LL * 6LL * 6LL * 6LL * 2LL || q != 6LL * 6LL * 6LL * 6LL) + abort (); + p = 1LL; + q = 1LL; + #pragma omp parallel + #pragma omp single + foo (&p, &q); + if (p != 6LL * 6LL * 6LL * 6LL * 6LL * 2LL || q != 6LL * 6LL * 6LL * 6LL) + abort (); + return 0; +}