diff options
author | rth <rth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-06-09 22:08:55 +0000 |
---|---|---|
committer | rth <rth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-06-09 22:08:55 +0000 |
commit | ba893327c7f139aebe0f09b07dd79fd879a0222d (patch) | |
tree | 98eb377c774c5cc06d2f045c4c2f3a387829b617 /libgomp | |
parent | 8a5d137dbca185c626aa590df1a66df61080c6a7 (diff) | |
download | gcc-ba893327c7f139aebe0f09b07dd79fd879a0222d.tar.gz |
* env.c (gomp_nthreads_var): Change to unsigned long.
(gomp_run_sched_chunk): Likewise.
(parse_unsigned_long): Rename from parse_num_threads and generalize.
(initialize_env): Initialize gomp_thread_attr.
* libgomp.h (gomp_nthreads_var): Update decl.
(gomp_run_sched_chunk): Likewise.
(gomp_thread_attr): Declare.
* team.c (gomp_thread_attr): Export.
(initialize_team): Don't initialize it.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114525 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgomp')
-rw-r--r-- | libgomp/ChangeLog | 12 | ||||
-rw-r--r-- | libgomp/env.c | 49 | ||||
-rw-r--r-- | libgomp/libgomp.h | 7 | ||||
-rw-r--r-- | libgomp/team.c | 5 |
4 files changed, 56 insertions, 17 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 07d0ff3376d..4069e2dbb6d 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,15 @@ +2006-06-09 Richard Henderson <rth@redhat.com> + + * env.c (gomp_nthreads_var): Change to unsigned long. + (gomp_run_sched_chunk): Likewise. + (parse_unsigned_long): Rename from parse_num_threads and generalize. + (initialize_env): Initialize gomp_thread_attr. + * libgomp.h (gomp_nthreads_var): Update decl. + (gomp_run_sched_chunk): Likewise. + (gomp_thread_attr): Declare. + * team.c (gomp_thread_attr): Export. + (initialize_team): Don't initialize it. + 2006-06-09 Jakub Jelinek <jakub@redhat.com> PR fortran/27916 diff --git a/libgomp/env.c b/libgomp/env.c index 985f9329b23..d42e68e6a3c 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -32,13 +32,15 @@ #include "libgomp_f.h" #include <stdlib.h> #include <string.h> +#include <limits.h> +#include <errno.h> -unsigned gomp_nthreads_var = 1; +unsigned long gomp_nthreads_var = 1; bool gomp_dyn_var = false; bool gomp_nest_var = false; enum gomp_schedule_type gomp_run_sched_var = GFS_DYNAMIC; -unsigned gomp_run_sched_chunk = 1; +unsigned long gomp_run_sched_chunk = 1; /* Parse the OMP_SCHEDULE environment variable. */ @@ -98,33 +100,35 @@ parse_schedule (void) return; } -/* Parse the OMP_NUM_THREADS environment varible. Return true if one was +/* Parse an unsigned long environment varible. Return true if one was present and it was successfully parsed. */ static bool -parse_num_threads (void) +parse_unsigned_long (const char *name, unsigned long *pvalue) { char *env, *end; + unsigned long value; - env = getenv ("OMP_NUM_THREADS"); + env = getenv (name); if (env == NULL) return false; if (*env == '\0') goto invalid; - gomp_nthreads_var = strtoul (env, &end, 10); + value = strtoul (env, &end, 10); if (*end != '\0') goto invalid; + + *pvalue = value; return true; invalid: - gomp_error ("Invalid value for enviroment variable OMP_NUM_THREADS"); - gomp_nthreads_var = 1; + gomp_error ("Invalid value for environment variable %s", name); return false; } -/* Parse a boolean value for environement variable NAME and store the +/* Parse a boolean value for environment variable NAME and store the result in VALUE. */ static void @@ -141,20 +145,43 @@ parse_boolean (const char *name, bool *value) else if (strcmp (env, "false") == 0) *value = false; else - gomp_error ("Invalid value for environement variable %s", name); + gomp_error ("Invalid value for environment variable %s", name); } static void __attribute__((constructor)) initialize_env (void) { + unsigned long stacksize; + /* Do a compile time check that mkomp_h.pl did good job. */ omp_check_defines (); parse_schedule (); parse_boolean ("OMP_DYNAMIC", &gomp_dyn_var); parse_boolean ("OMP_NESTED", &gomp_nest_var); - if (!parse_num_threads ()) + if (!parse_unsigned_long ("OMP_NUM_THREADS", &gomp_nthreads_var)) gomp_init_num_threads (); + + /* Not strictly environment related, but ordering constructors is tricky. */ + pthread_attr_init (&gomp_thread_attr); + pthread_attr_setdetachstate (&gomp_thread_attr, PTHREAD_CREATE_DETACHED); + + if (parse_unsigned_long ("OMP_STACKSIZE", &stacksize)) + { + stacksize *= 1024; + if (stacksize < PTHREAD_STACK_MIN) + gomp_error ("Stack size less than minimum of %luk", + PTHREAD_STACK_MIN / 1024ul + + (PTHREAD_STACK_MIN % 1024 != 0)); + else + { + int err = pthread_attr_setstacksize (&gomp_thread_attr, stacksize); + if (err == EINVAL) + gomp_error ("Stack size larger than system limit"); + else if (err != 0) + gomp_error ("Stack size change failed: %s", strerror (err)); + } + } } diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index 927dea5b6b7..47e68e69cfe 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -237,11 +237,14 @@ static inline struct gomp_thread *gomp_thread (void) /* These are the OpenMP 2.5 internal control variables described in section 2.3. At least those that correspond to environment variables. */ -extern unsigned gomp_nthreads_var; +extern unsigned long gomp_nthreads_var; extern bool gomp_dyn_var; extern bool gomp_nest_var; extern enum gomp_schedule_type gomp_run_sched_var; -extern unsigned gomp_run_sched_chunk; +extern unsigned long gomp_run_sched_chunk; + +/* The attributes to be used during thread creation. */ +extern pthread_attr_t gomp_thread_attr; /* Function prototypes. */ diff --git a/libgomp/team.c b/libgomp/team.c index a4020fc37c4..060f4ea2c6b 100644 --- a/libgomp/team.c +++ b/libgomp/team.c @@ -39,7 +39,7 @@ static unsigned gomp_threads_size; static unsigned gomp_threads_used; /* This attribute contains PTHREAD_CREATE_DETACHED. */ -static pthread_attr_t gomp_thread_attr; +pthread_attr_t gomp_thread_attr; /* This barrier holds and releases threads waiting in gomp_threads. */ static gomp_barrier_t gomp_threads_dock; @@ -338,7 +338,4 @@ initialize_team (void) thr = &initial_thread_tls_data; #endif gomp_sem_init (&thr->release, 0); - - pthread_attr_init (&gomp_thread_attr); - pthread_attr_setdetachstate (&gomp_thread_attr, PTHREAD_CREATE_DETACHED); } |