diff options
author | Jakub Jelinek <jakub@redhat.com> | 2010-03-22 16:16:52 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2010-03-22 16:16:52 +0100 |
commit | 80f046ccedcffce37a508800f7e552338257f620 (patch) | |
tree | 655886a8d69ffcdc399d52cfe655719423ef7e2b /libgomp | |
parent | 57fd5f9525f36d3df45345c343e4086aaa452750 (diff) | |
download | gcc-80f046ccedcffce37a508800f7e552338257f620.zip gcc-80f046ccedcffce37a508800f7e552338257f620.tar.gz gcc-80f046ccedcffce37a508800f7e552338257f620.tar.bz2 |
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
Diffstat (limited to 'libgomp')
-rw-r--r-- | libgomp/ChangeLog | 10 | ||||
-rw-r--r-- | libgomp/env.c | 17 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c/pr42942.c | 61 |
3 files changed, 81 insertions, 7 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 420f354..b9f4a8a 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,13 @@ +2010-03-22 Jakub Jelinek <jakub@redhat.com> + + 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 <grosser@fim.uni-passau.de> PR middle-end/42644 diff --git a/libgomp/env.c b/libgomp/env.c index c870433..3eb51e8 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 <rth@redhat.com>. 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 0000000..5d57852 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/pr42942.c @@ -0,0 +1,61 @@ +/* PR libgomp/42942 */ +/* { dg-do run } */ + +#include <omp.h> +#include <stdlib.h> + +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; +} |