From patchwork Wed Oct 9 09:33:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 281765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3E5012C00A8 for ; Wed, 9 Oct 2013 20:33:32 +1100 (EST) 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=ZU00uzCaRMzBsbxu7mEfoGtxriVax25NkrqxOtzRaOg UjkC6Nv6QtIJ6Ju8IaoXvkIQDRUgWOwce8HkSnW4ZduoEjKl0r/ZGcd6Byub4JU2 d+3axlKnB4uFW5DFh6L7MdqHMANiWde6fqfsddQcVlM+KC6rhaVyknQwJiHfzXyU = 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=vsgPcEI3h8VPi05gS1bugu+uuTU=; b=cq5KIyivwebQ8AWUd N6BXF+24ebeE6OzVirHSutwL1IGE1ZDAKy3i9AzEs7l+CzWY9s2FbplKUyuJ2Y95 LOYoWYuBZDBuDtyo5BSighi1+NvTB6q9KYyfhBJCg1xrEJHdRvRHWLx0fSlb6OeZ oJVxsxNwQEzY8/58X/LWNqhyxc= Received: (qmail 24724 invoked by alias); 9 Oct 2013 09:33:27 -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 24715 invoked by uid 89); 9 Oct 2013 09:33:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 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; Wed, 09 Oct 2013 09:33:26 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r999XN43019136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Oct 2013 05:33:24 -0400 Received: from tucnak.zalov.cz (vpn1-4-26.ams2.redhat.com [10.36.4.26]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r999XLhR026708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 9 Oct 2013 05:33:22 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id r999XKt1029512 for ; Wed, 9 Oct 2013 11:33:20 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id r999XK7C029511 for gcc-patches@gcc.gnu.org; Wed, 9 Oct 2013 11:33:20 +0200 Date: Wed, 9 Oct 2013 11:33:20 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [4.8] Fix OMP_THREAD_LIMIT libgomp handling Message-ID: <20131009093320.GN30970@tucnak.zalov.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! This is the minimal fix for the issue mentioned in http://gcc.gnu.org/ml/gcc-patches/2013-10/msg00333.html that is being fixed as part of gomp-4_0-branch merge to trunk, but for 4.8 I've applied this fix instead. The testcase also includes the follow-up fix from http://gcc.gnu.org/ml/gcc-patches/2013-10/msg00497.html Bootstrapped/regtested on x86_64-linux and i686-linux, committed to 4.8 branch. 2013-10-09 Jakub Jelinek * parallel.c (GOMP_parallel_end): Remember team->nthreads and call gomp_team_end before adjusting gomp_remaining_threads_count, increment gomp_remaining_threads_count instead of decrementing it again. * testsuite/libgomp.c/thread-limit-1.c: New test. Jakub --- libgomp/parallel.c.jj 2013-03-16 08:07:43.000000000 +0100 +++ libgomp/parallel.c 2013-10-09 09:10:38.215245390 +0200 @@ -115,19 +115,22 @@ GOMP_parallel_end (void) { struct gomp_thread *thr = gomp_thread (); struct gomp_team *team = thr->ts.team; - if (team && team->nthreads > 1) + unsigned int nthreads = team ? team->nthreads : 1; + gomp_team_end (); + if (nthreads > 1) { #ifdef HAVE_SYNC_BUILTINS __sync_fetch_and_add (&gomp_remaining_threads_count, - 1UL - team->nthreads); + nthreads - 1); #else gomp_mutex_lock (&gomp_remaining_threads_lock); - gomp_remaining_threads_count -= team->nthreads - 1; + gomp_remaining_threads_count += nthreads - 1; gomp_mutex_unlock (&gomp_remaining_threads_lock); #endif } } - gomp_team_end (); + else + gomp_team_end (); } --- libgomp/testsuite/libgomp.c/thread-limit-1.c.jj 2013-10-09 09:05:35.702854964 +0200 +++ libgomp/testsuite/libgomp.c/thread-limit-1.c 2013-10-08 20:30:47.000000000 +0200 @@ -0,0 +1,41 @@ +/* { dg-do run } */ +/* { dg-set-target-env-var OMP_THREAD_LIMIT "6" } */ + +#include +#include + +int +main () +{ + if (omp_get_thread_limit () != 6) + return 0; + omp_set_dynamic (0); + omp_set_nested (1); + #pragma omp parallel num_threads (3) + if (omp_get_num_threads () != 3) + abort (); + #pragma omp parallel num_threads (3) + if (omp_get_num_threads () != 3) + abort (); + #pragma omp parallel num_threads (8) + if (omp_get_num_threads () > 6) + abort (); + #pragma omp parallel num_threads (6) + if (omp_get_num_threads () != 6) + abort (); + int cnt = 0; + #pragma omp parallel num_threads (5) + #pragma omp parallel num_threads (5) + #pragma omp parallel num_threads (2) + { + int v; + #pragma omp atomic capture + v = ++cnt; + if (v > 6) + abort (); + usleep (10000); + #pragma omp atomic + --cnt; + } + return 0; +}