From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 536A63930B3F for ; Tue, 28 Jun 2022 15:07:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 536A63930B3F Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-193-oaKAu_xJPZiSmyYezAqIBg-1; Tue, 28 Jun 2022 11:07:30 -0400 X-MC-Unique: oaKAu_xJPZiSmyYezAqIBg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6F49C38149A8; Tue, 28 Jun 2022 15:07:30 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F0D92166B26; Tue, 28 Jun 2022 15:07:29 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 25SF7RZE3977849 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Jun 2022 17:07:27 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 25SF7QiM3977848; Tue, 28 Jun 2022 17:07:26 +0200 Date: Tue, 28 Jun 2022 17:07:26 +0200 From: Jakub Jelinek To: Chung-Lin Tang , Tobias Burnus , gcc-patches Subject: Re: [PATCH, libgomp] Fix chunk_size<1 for dynamic schedule Message-ID: Reply-To: Jakub Jelinek References: <13568991-7359-9149-04fa-cde2245f108c@codesourcery.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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: , X-List-Received-Date: Tue, 28 Jun 2022 15:07:37 -0000 On Tue, Jun 28, 2022 at 04:06:14PM +0200, Jakub Jelinek via Gcc-patches wrote: > On Thu, Jun 23, 2022 at 11:47:59PM +0800, Chung-Lin Tang wrote: > > with the way that chunk_size < 1 is handled for gomp_iter_dynamic_next: > > > > (1) chunk_size <= -1: wraps into large unsigned value, seems to work though. > > (2) chunk_size == 0: infinite loop > > > > The (2) behavior is obviously not desired. This patch fixes this by changing > > Why? It is a user error, undefined behavior, we shouldn't slow down valid > code for users who don't bother reading the standard. > > E.g. OpenMP 5.1 [132:14] says clearly: > "chunk_size must be a loop invariant integer expression with a positive > value." > and omp_set_schedule for chunk_size < 1 should use a default value (which it > does). > > For OMP_SCHEDULE the standard says it is implementation-defined what happens > if the format isn't the specified one, so I guess the env.c change > could be acceptable (though without it it is fine too), but the Though, seems we quietly transform the only problematic value (0) in there to 1 for selected schedules which don't accept 0 as "unspecified" and for the negative values, we'll have large ulong chunk sizes which is fine. If we really want help people debugging their programs, we could introduce something like -fsanitize=openmp that would add runtime instrumentation of a lot of OpenMP restrictions and could diagnose it with nice diagnostics, perhaps using some extra library and with runtime checks in generated code. Jakub