From 80f046ccedcffce37a508800f7e552338257f620 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 22 Mar 2010 16:16:52 +0100 Subject: [PATCH] re PR libgomp/42942 (OpenMP omp_set_max_active_levels(0) isn't resetting value) PR libgomp/42942 * env.c (parse_unsigned_long): Add ALLOW_ZERO argument. (initialize_env): Adjust callers. (omp_set_max_active_levels): Set gomp_max_active_levels_var even when the argument is 0. * testsuite/libgomp.c/pr42942.c: New test. From-SVN: r157635 --- libgomp/ChangeLog | 10 +++++ libgomp/env.c | 17 +++++--- libgomp/testsuite/libgomp.c/pr42942.c | 61 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 libgomp/testsuite/libgomp.c/pr42942.c diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 420f354c51a..b9f4a8a883e 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,13 @@ +2010-03-22 Jakub Jelinek + + PR libgomp/42942 + * env.c (parse_unsigned_long): Add ALLOW_ZERO argument. + (initialize_env): Adjust callers. + (omp_set_max_active_levels): Set gomp_max_active_levels_var even + when the argument is 0. + + * testsuite/libgomp.c/pr42942.c: New test. + 2010-03-08 Tobias Grosser PR middle-end/42644 diff --git a/libgomp/env.c b/libgomp/env.c index c870433f332..3eb51e8a7d6 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 + Free Software Foundation, Inc. Contributed by Richard Henderson . This file is part of the GNU OpenMP Library (libgomp). @@ -145,7 +146,7 @@ parse_schedule (void) present and it was successfully parsed. */ static bool -parse_unsigned_long (const char *name, unsigned long *pvalue) +parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero) { char *env, *end; unsigned long value; @@ -161,7 +162,7 @@ parse_unsigned_long (const char *name, unsigned long *pvalue) errno = 0; value = strtoul (env, &end, 10); - if (errno || (long) value <= 0) + if (errno || (long) value <= 0 - allow_zero) goto invalid; while (isspace ((unsigned char) *end)) @@ -481,8 +482,9 @@ initialize_env (void) parse_schedule (); parse_boolean ("OMP_DYNAMIC", &gomp_global_icv.dyn_var); parse_boolean ("OMP_NESTED", &gomp_global_icv.nest_var); - parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var); - parse_unsigned_long ("OMP_THREAD_LIMIT", &gomp_thread_limit_var); + parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var, + true); + parse_unsigned_long ("OMP_THREAD_LIMIT", &gomp_thread_limit_var, false); if (gomp_thread_limit_var != ULONG_MAX) gomp_remaining_threads_count = gomp_thread_limit_var - 1; #ifndef HAVE_SYNC_BUILTINS @@ -490,7 +492,8 @@ initialize_env (void) #endif gomp_init_num_threads (); gomp_available_cpus = gomp_global_icv.nthreads_var; - if (!parse_unsigned_long ("OMP_NUM_THREADS", &gomp_global_icv.nthreads_var)) + if (!parse_unsigned_long ("OMP_NUM_THREADS", &gomp_global_icv.nthreads_var, + false)) gomp_global_icv.nthreads_var = gomp_available_cpus; if (parse_affinity ()) gomp_init_affinity (); @@ -632,7 +635,7 @@ omp_get_thread_limit (void) void omp_set_max_active_levels (int max_levels) { - if (max_levels > 0) + if (max_levels >= 0) gomp_max_active_levels_var = max_levels; } diff --git a/libgomp/testsuite/libgomp.c/pr42942.c b/libgomp/testsuite/libgomp.c/pr42942.c new file mode 100644 index 00000000000..5d57852450a --- /dev/null +++ b/libgomp/testsuite/libgomp.c/pr42942.c @@ -0,0 +1,61 @@ +/* PR libgomp/42942 */ +/* { dg-do run } */ + +#include +#include + +int +main (void) +{ + int e = 0; + omp_set_dynamic (0); + omp_set_nested (1); + omp_set_max_active_levels (1); + if (omp_get_max_active_levels () != 1) + abort (); +#pragma omp parallel num_threads(2) reduction(|:e) + if (!omp_in_parallel () + || omp_get_num_threads () != 2) + e = 1; + else +#pragma omp parallel num_threads(2) reduction(|:e) + if (!omp_in_parallel () + || omp_get_num_threads () != 1) + e = 1; + if (e) + abort (); + omp_set_max_active_levels (0); + if (omp_get_max_active_levels () != 0) + abort (); +#pragma omp parallel num_threads(2) reduction(|:e) + if (omp_in_parallel () + || omp_get_num_threads () != 1) + e = 1; + else +#pragma omp parallel num_threads(2) reduction(|:e) + if (omp_in_parallel () + || omp_get_num_threads () != 1) + e = 1; + if (e) + abort (); + omp_set_max_active_levels (2); + if (omp_get_max_active_levels () != 2) + abort (); +#pragma omp parallel num_threads(2) reduction(|:e) + if (!omp_in_parallel () + || omp_get_num_threads () != 2) + e = 1; + else +#pragma omp parallel num_threads(2) reduction(|:e) + if (!omp_in_parallel () + || omp_get_num_threads () != 2) + e = 1; + else +#pragma omp parallel num_threads(2) reduction(|:e) + if (!omp_in_parallel () + || omp_get_num_threads () != 1) + e = 1; + if (e) + abort (); + return 0; +}