From: Chung-Lin Tang <cltang@codesourcery.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
Catherine Moore <clm@codesourcery.com>,
Tobias Burnus <tobias@codesourcery.com>
Subject: [PATCH, libgomp] Fix chunk_size<1 for dynamic schedule
Date: Thu, 23 Jun 2022 23:47:59 +0800 [thread overview]
Message-ID: <13568991-7359-9149-04fa-cde2245f108c@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 802 bytes --]
Hi Jakub,
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
the chunk_size initialization in gomp_loop_init to "max(1,chunk_size)"
The OMP_SCHEDULE parsing in libgomp/env.c has also been adjusted to reject
negative values.
Tested without regressions, and a new testcase for the infinite loop behavior added.
Okay for trunk?
Thanks,
Chung-Lin
libgomp/ChangeLog:
* env.c (parse_schedule): Make negative values invalid for chunk_size.
* loop.c (gomp_loop_init): For non-STATIC schedule and chunk_size <= 0,
set initialized chunk_size to 1.
* testsuite/libgomp.c/loop-28.c: New test.
[-- Attachment #2: chunk_size.patch --]
[-- Type: text/plain, Size: 1411 bytes --]
diff --git a/libgomp/env.c b/libgomp/env.c
index 1c4ee894515..dff07617e15 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -182,6 +182,8 @@ parse_schedule (void)
goto invalid;
errno = 0;
+ if (*env == '-')
+ goto invalid;
value = strtoul (env, &end, 10);
if (errno || end == env)
goto invalid;
diff --git a/libgomp/loop.c b/libgomp/loop.c
index be85162bb1e..018b4e9a8bd 100644
--- a/libgomp/loop.c
+++ b/libgomp/loop.c
@@ -41,7 +41,7 @@ gomp_loop_init (struct gomp_work_share *ws, long start, long end, long incr,
enum gomp_schedule_type sched, long chunk_size)
{
ws->sched = sched;
- ws->chunk_size = chunk_size;
+ ws->chunk_size = (sched == GFS_STATIC || chunk_size > 1) ? chunk_size : 1;
/* Canonicalize loops that have zero iterations to ->next == ->end. */
ws->end = ((incr > 0 && start > end) || (incr < 0 && start < end))
? start : end;
diff --git a/libgomp/testsuite/libgomp.c/loop-28.c b/libgomp/testsuite/libgomp.c/loop-28.c
new file mode 100644
index 00000000000..e3f852046f4
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/loop-28.c
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-timeout 10 } */
+
+void __attribute__((noinline))
+foo (int a[], int n, int chunk_size)
+{
+ #pragma omp parallel for schedule (dynamic,chunk_size)
+ for (int i = 0; i < n; i++)
+ a[i] = i;
+}
+
+int main (void)
+{
+ int a[100];
+ foo (a, 100, 0);
+ return 0;
+}
next reply other threads:[~2022-06-23 15:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-23 15:47 Chung-Lin Tang [this message]
2022-06-28 14:06 ` Jakub Jelinek
2022-06-28 15:07 ` Jakub Jelinek
2022-08-04 13:17 ` Chung-Lin Tang
2022-08-04 13:31 ` Koning, Paul
2022-08-26 8:15 ` [PING] " Chung-Lin Tang
2022-09-09 10:08 ` [PING x2] " Chung-Lin Tang
2022-09-13 14:07 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13568991-7359-9149-04fa-cde2245f108c@codesourcery.com \
--to=cltang@codesourcery.com \
--cc=clm@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=tobias@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).