OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [libgomp/] [env.c] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
   Contributed by Richard Henderson <rth@redhat.com>.
   Contributed by Richard Henderson <rth@redhat.com>.
 
 
   This file is part of the GNU OpenMP Library (libgomp).
   This file is part of the GNU OpenMP Library (libgomp).
 
 
   Libgomp is free software; you can redistribute it and/or modify it
   Libgomp is free software; you can redistribute it and/or modify it
   under the terms of the GNU Lesser General Public License as published by
   under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation; either version 2.1 of the License, or
   the Free Software Foundation; either version 2.1 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
   FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
   more details.
   more details.
 
 
   You should have received a copy of the GNU Lesser General Public License
   You should have received a copy of the GNU Lesser General Public License
   along with libgomp; see the file COPYING.LIB.  If not, write to the
   along with libgomp; see the file COPYING.LIB.  If not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   MA 02110-1301, USA.  */
   MA 02110-1301, USA.  */
 
 
/* As a special exception, if you link this library with other files, some
/* As a special exception, if you link this library with other files, some
   of which are compiled with GCC, to produce an executable, this library
   of which are compiled with GCC, to produce an executable, this library
   does not by itself cause the resulting executable to be covered by the
   does not by itself cause the resulting executable to be covered by the
   GNU General Public License.  This exception does not however invalidate
   GNU General Public License.  This exception does not however invalidate
   any other reasons why the executable file might be covered by the GNU
   any other reasons why the executable file might be covered by the GNU
   General Public License.  */
   General Public License.  */
 
 
/* This file defines the OpenMP internal control variables, and arranges
/* This file defines the OpenMP internal control variables, and arranges
   for them to be initialized from environment variables at startup.  */
   for them to be initialized from environment variables at startup.  */
 
 
#include "libgomp.h"
#include "libgomp.h"
#include "libgomp_f.h"
#include "libgomp_f.h"
#include <ctype.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <limits.h>
#include <limits.h>
#include <errno.h>
#include <errno.h>
 
 
 
 
unsigned long gomp_nthreads_var = 1;
unsigned long gomp_nthreads_var = 1;
bool gomp_dyn_var = false;
bool gomp_dyn_var = false;
bool gomp_nest_var = false;
bool gomp_nest_var = false;
enum gomp_schedule_type gomp_run_sched_var = GFS_DYNAMIC;
enum gomp_schedule_type gomp_run_sched_var = GFS_DYNAMIC;
unsigned long gomp_run_sched_chunk = 1;
unsigned long gomp_run_sched_chunk = 1;
 
 
/* Parse the OMP_SCHEDULE environment variable.  */
/* Parse the OMP_SCHEDULE environment variable.  */
 
 
static void
static void
parse_schedule (void)
parse_schedule (void)
{
{
  char *env, *end;
  char *env, *end;
  unsigned long value;
  unsigned long value;
 
 
  env = getenv ("OMP_SCHEDULE");
  env = getenv ("OMP_SCHEDULE");
  if (env == NULL)
  if (env == NULL)
    return;
    return;
 
 
  while (isspace ((unsigned char) *env))
  while (isspace ((unsigned char) *env))
    ++env;
    ++env;
  if (strncasecmp (env, "static", 6) == 0)
  if (strncasecmp (env, "static", 6) == 0)
    {
    {
      gomp_run_sched_var = GFS_STATIC;
      gomp_run_sched_var = GFS_STATIC;
      env += 6;
      env += 6;
    }
    }
  else if (strncasecmp (env, "dynamic", 7) == 0)
  else if (strncasecmp (env, "dynamic", 7) == 0)
    {
    {
      gomp_run_sched_var = GFS_DYNAMIC;
      gomp_run_sched_var = GFS_DYNAMIC;
      env += 7;
      env += 7;
    }
    }
  else if (strncasecmp (env, "guided", 6) == 0)
  else if (strncasecmp (env, "guided", 6) == 0)
    {
    {
      gomp_run_sched_var = GFS_GUIDED;
      gomp_run_sched_var = GFS_GUIDED;
      env += 6;
      env += 6;
    }
    }
  else
  else
    goto unknown;
    goto unknown;
 
 
  while (isspace ((unsigned char) *env))
  while (isspace ((unsigned char) *env))
    ++env;
    ++env;
  if (*env == '\0')
  if (*env == '\0')
    return;
    return;
  if (*env++ != ',')
  if (*env++ != ',')
    goto unknown;
    goto unknown;
  while (isspace ((unsigned char) *env))
  while (isspace ((unsigned char) *env))
    ++env;
    ++env;
  if (*env == '\0')
  if (*env == '\0')
    goto invalid;
    goto invalid;
 
 
  errno = 0;
  errno = 0;
  value = strtoul (env, &end, 10);
  value = strtoul (env, &end, 10);
  if (errno)
  if (errno)
    goto invalid;
    goto invalid;
 
 
  while (isspace ((unsigned char) *end))
  while (isspace ((unsigned char) *end))
    ++end;
    ++end;
  if (*end != '\0')
  if (*end != '\0')
    goto invalid;
    goto invalid;
 
 
  gomp_run_sched_chunk = value;
  gomp_run_sched_chunk = value;
  return;
  return;
 
 
 unknown:
 unknown:
  gomp_error ("Unknown value for environment variable OMP_SCHEDULE");
  gomp_error ("Unknown value for environment variable OMP_SCHEDULE");
  return;
  return;
 
 
 invalid:
 invalid:
  gomp_error ("Invalid value for chunk size in "
  gomp_error ("Invalid value for chunk size in "
              "environment variable OMP_SCHEDULE");
              "environment variable OMP_SCHEDULE");
  return;
  return;
}
}
 
 
/* Parse an unsigned long environment varible.  Return true if one was
/* Parse an unsigned long environment varible.  Return true if one was
   present and it was successfully parsed.  */
   present and it was successfully parsed.  */
 
 
static bool
static bool
parse_unsigned_long (const char *name, unsigned long *pvalue)
parse_unsigned_long (const char *name, unsigned long *pvalue)
{
{
  char *env, *end;
  char *env, *end;
  unsigned long value;
  unsigned long value;
 
 
  env = getenv (name);
  env = getenv (name);
  if (env == NULL)
  if (env == NULL)
    return false;
    return false;
 
 
  while (isspace ((unsigned char) *env))
  while (isspace ((unsigned char) *env))
    ++env;
    ++env;
  if (*env == '\0')
  if (*env == '\0')
    goto invalid;
    goto invalid;
 
 
  errno = 0;
  errno = 0;
  value = strtoul (env, &end, 10);
  value = strtoul (env, &end, 10);
  if (errno || (long) value <= 0)
  if (errno || (long) value <= 0)
    goto invalid;
    goto invalid;
 
 
  while (isspace ((unsigned char) *end))
  while (isspace ((unsigned char) *end))
    ++end;
    ++end;
  if (*end != '\0')
  if (*end != '\0')
    goto invalid;
    goto invalid;
 
 
  *pvalue = value;
  *pvalue = value;
  return true;
  return true;
 
 
 invalid:
 invalid:
  gomp_error ("Invalid value for environment variable %s", name);
  gomp_error ("Invalid value for environment variable %s", name);
  return false;
  return false;
}
}
 
 
/* Parse a boolean value for environment variable NAME and store the
/* Parse a boolean value for environment variable NAME and store the
   result in VALUE.  */
   result in VALUE.  */
 
 
static void
static void
parse_boolean (const char *name, bool *value)
parse_boolean (const char *name, bool *value)
{
{
  const char *env;
  const char *env;
 
 
  env = getenv (name);
  env = getenv (name);
  if (env == NULL)
  if (env == NULL)
    return;
    return;
 
 
  while (isspace ((unsigned char) *env))
  while (isspace ((unsigned char) *env))
    ++env;
    ++env;
  if (strncasecmp (env, "true", 4) == 0)
  if (strncasecmp (env, "true", 4) == 0)
    {
    {
      *value = true;
      *value = true;
      env += 4;
      env += 4;
    }
    }
  else if (strncasecmp (env, "false", 5) == 0)
  else if (strncasecmp (env, "false", 5) == 0)
    {
    {
      *value = false;
      *value = false;
      env += 5;
      env += 5;
    }
    }
  else
  else
    env = "X";
    env = "X";
  while (isspace ((unsigned char) *env))
  while (isspace ((unsigned char) *env))
    ++env;
    ++env;
  if (*env != '\0')
  if (*env != '\0')
    gomp_error ("Invalid value for environment variable %s", name);
    gomp_error ("Invalid value for environment variable %s", name);
}
}
 
 
static void __attribute__((constructor))
static void __attribute__((constructor))
initialize_env (void)
initialize_env (void)
{
{
  unsigned long stacksize;
  unsigned long stacksize;
 
 
  /* Do a compile time check that mkomp_h.pl did good job.  */
  /* Do a compile time check that mkomp_h.pl did good job.  */
  omp_check_defines ();
  omp_check_defines ();
 
 
  parse_schedule ();
  parse_schedule ();
  parse_boolean ("OMP_DYNAMIC", &gomp_dyn_var);
  parse_boolean ("OMP_DYNAMIC", &gomp_dyn_var);
  parse_boolean ("OMP_NESTED", &gomp_nest_var);
  parse_boolean ("OMP_NESTED", &gomp_nest_var);
  if (!parse_unsigned_long ("OMP_NUM_THREADS", &gomp_nthreads_var))
  if (!parse_unsigned_long ("OMP_NUM_THREADS", &gomp_nthreads_var))
    gomp_init_num_threads ();
    gomp_init_num_threads ();
 
 
  /* Not strictly environment related, but ordering constructors is tricky.  */
  /* Not strictly environment related, but ordering constructors is tricky.  */
  pthread_attr_init (&gomp_thread_attr);
  pthread_attr_init (&gomp_thread_attr);
  pthread_attr_setdetachstate (&gomp_thread_attr, PTHREAD_CREATE_DETACHED);
  pthread_attr_setdetachstate (&gomp_thread_attr, PTHREAD_CREATE_DETACHED);
 
 
  if (parse_unsigned_long ("GOMP_STACKSIZE", &stacksize))
  if (parse_unsigned_long ("GOMP_STACKSIZE", &stacksize))
    {
    {
      int err;
      int err;
 
 
      stacksize *= 1024;
      stacksize *= 1024;
      err = pthread_attr_setstacksize (&gomp_thread_attr, stacksize);
      err = pthread_attr_setstacksize (&gomp_thread_attr, stacksize);
 
 
#ifdef PTHREAD_STACK_MIN
#ifdef PTHREAD_STACK_MIN
      if (err == EINVAL)
      if (err == EINVAL)
        {
        {
          if (stacksize < PTHREAD_STACK_MIN)
          if (stacksize < PTHREAD_STACK_MIN)
            gomp_error ("Stack size less than minimum of %luk",
            gomp_error ("Stack size less than minimum of %luk",
                        PTHREAD_STACK_MIN / 1024ul
                        PTHREAD_STACK_MIN / 1024ul
                        + (PTHREAD_STACK_MIN % 1024 != 0));
                        + (PTHREAD_STACK_MIN % 1024 != 0));
          else
          else
            gomp_error ("Stack size larger than system limit");
            gomp_error ("Stack size larger than system limit");
        }
        }
      else
      else
#endif
#endif
      if (err != 0)
      if (err != 0)
        gomp_error ("Stack size change failed: %s", strerror (err));
        gomp_error ("Stack size change failed: %s", strerror (err));
    }
    }
}
}
 
 


/* The public OpenMP API routines that access these variables.  */
/* The public OpenMP API routines that access these variables.  */
 
 
void
void
omp_set_num_threads (int n)
omp_set_num_threads (int n)
{
{
  gomp_nthreads_var = (n > 0 ? n : 1);
  gomp_nthreads_var = (n > 0 ? n : 1);
}
}
 
 
void
void
omp_set_dynamic (int val)
omp_set_dynamic (int val)
{
{
  gomp_dyn_var = val;
  gomp_dyn_var = val;
}
}
 
 
int
int
omp_get_dynamic (void)
omp_get_dynamic (void)
{
{
  return gomp_dyn_var;
  return gomp_dyn_var;
}
}
 
 
void
void
omp_set_nested (int val)
omp_set_nested (int val)
{
{
  gomp_nest_var = val;
  gomp_nest_var = val;
}
}
 
 
int
int
omp_get_nested (void)
omp_get_nested (void)
{
{
  return gomp_nest_var;
  return gomp_nest_var;
}
}
 
 
ialias (omp_set_dynamic)
ialias (omp_set_dynamic)
ialias (omp_set_nested)
ialias (omp_set_nested)
ialias (omp_set_num_threads)
ialias (omp_set_num_threads)
ialias (omp_get_dynamic)
ialias (omp_get_dynamic)
ialias (omp_get_nested)
ialias (omp_get_nested)
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.