public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gomp 4.0] Handle OMP_DISPLAY_ENV
@ 2013-03-19 15:24 Tobias Burnus
  2013-03-19 17:24 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Tobias Burnus @ 2013-03-19 15:24 UTC (permalink / raw)
  To: gcc patches

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

Attached is a first shot for OMP_DISPLAY_ENV. One could think about how 
to handle GOMP_CPU_AFFINITY and OMP_WAIT_POLICY. I currently print an 
empty list for affinity (although using GOMP_CPU_AFFINITY='' leads to a 
warning that the list is empty) and for OMP_WAIT_POLICY, an unset 
variable is handled as something between ACTIVE and PASSIVE; the patch 
prints PASSIVE in that case.

Build and regtested on x86-64-gnu-linux.
OK for the gomp-4_0-branch - after is has been created?

Tobias

[-- Attachment #2: gomp4-display-env.diff --]
[-- Type: text/x-patch, Size: 3840 bytes --]

2013-03-19  Tobias Burnus  <burnus@net-b.de>

	* env.c (handle_omp_display_env): New function.
	(initialize_env): Use it.

diff --git a/libgomp/env.c b/libgomp/env.c
index 65cbba8..e228bd9 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -29,6 +29,8 @@
 #include "libgomp_f.h"
 #include <ctype.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>	/* For PRIu64.  */
 #ifdef STRING_WITH_STRINGS
 # include <string.h>
 # include <strings.h>
@@ -565,6 +567,117 @@ parse_affinity (void)
   return false;
 }
 
+
+static void
+handle_omp_display_env (bool proc_bind, unsigned long stacksize,
+			int wait_policy)
+{
+  const char *env;
+  bool display = false;
+  bool verbose = false;
+  int i;
+
+  env = getenv ("OMP_DISPLAY_ENV");
+  if (env == NULL)
+    return;
+
+  while (isspace ((unsigned char) *env))
+    ++env;
+  if (strncasecmp (env, "true", 4) == 0)
+    {
+      env += 4;
+    }
+  else if (strncasecmp (env, "false", 5) == 0)
+    {
+      display = false;
+      env += 5;
+    }
+  else if (strncasecmp (env, "verbose", 7) == 0)
+    {
+      display = true;
+      verbose = true;
+      env += 7;
+    }
+  else
+    env = "X";
+  while (isspace ((unsigned char) *env))
+    ++env;
+  if (*env != '\0')
+    gomp_error ("Invalid value for environment variable OMP_DISPLAY_ENV");
+
+  if (!display)
+    return;
+
+  fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr);
+
+  fputs ("  _OPENMP = '201107'\n", stderr);
+  fprintf (stderr, "  OMP_DYNAMIC = '%s'\n",
+	   gomp_global_icv.dyn_var ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_NESTED = '%s'\n",
+	   gomp_global_icv.nest_var ? "TRUE" : "FALSE");
+
+  fprintf (stderr, "  OMP_NUM_THREADS = '%lu", gomp_global_icv.nthreads_var);
+  for (i = 1; i < gomp_nthreads_var_list_len; i++)
+    fprintf (stderr, ",%lu", gomp_nthreads_var_list[i]);
+  fputs ("'\n", stderr);
+
+  fprintf (stderr, "  OMP_SCHEDULE = '");
+  switch (gomp_global_icv.run_sched_var)
+    {
+    case GFS_RUNTIME:
+      fputs ("RUNTIME", stderr);
+      break;
+    case GFS_STATIC:
+      fputs ("STATIC", stderr);
+      break;
+    case GFS_DYNAMIC:
+      fputs ("DYNAMIC", stderr);
+      break;
+    case GFS_GUIDED:
+      fputs ("GUIDED", stderr);
+      break;
+    case GFS_AUTO:
+      fputs ("AUTO", stderr);
+      break;
+    }
+  fputs ("'\n", stderr);
+
+  fprintf (stderr, "  OMP_PROC_BIND = '%s'\n",
+	   proc_bind ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_STACKSIZE = '%lu'\n", stacksize);
+
+  /* GOMP's default value is actually neither active nor passive.  */
+  fprintf (stderr, "  OMP_WAIT_POLICY = '%s'\n",
+	   wait_policy > 0 ? "ACTIVE" : "PASSIVE");
+  fprintf (stderr, "  OMP_THREAD_LIMIT = '%lu'\n",
+	   gomp_thread_limit_var);
+  fprintf (stderr, "  OMP_MAX_ACTIVE_LEVELS = '%lu'\n",
+	   gomp_max_active_levels_var);
+
+/* FIXME: Unimplemented OpenMP 4.0 environment variables.
+  fprintf (stderr, "  OMP_PLACES = ''\n");
+  fprintf (stderr, "  OMP_CANCELLATION = ''\n");
+  fprintf (stderr, "  OMP_DEFAULT_DEVICE = ''\n"); */
+
+  if (verbose)
+    {
+      fputs ("  GOMP_CPU_AFFINITY = '", stderr);
+      if (gomp_cpu_affinity_len)
+	{
+	  fprintf (stderr, "%d", gomp_cpu_affinity[0]);
+	  for (i = 1; i < gomp_cpu_affinity_len; i++)
+	    fprintf (stderr, " %d", gomp_cpu_affinity[i]);
+	}
+      fputs ("'\n", stderr);
+      fprintf (stderr, "  GOMP_STACKSIZE = '%lu'\n", stacksize);
+      fprintf (stderr, "  GOMP_SPINCOUNT = '%"PRIu64"'\n",
+	       (uint64_t) gomp_spin_count_var);
+    }
+
+  fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr);
+}
+
+
 static void __attribute__((constructor))
 initialize_env (void)
 {
@@ -645,6 +758,8 @@ initialize_env (void)
       if (err != 0)
 	gomp_error ("Stack size change failed: %s", strerror (err));
     }
+
+  handle_omp_display_env (bind_var, stacksize, wait_policy);
 }
 
 \f

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gomp 4.0] Handle OMP_DISPLAY_ENV
  2013-03-19 15:24 [gomp 4.0] Handle OMP_DISPLAY_ENV Tobias Burnus
@ 2013-03-19 17:24 ` Jakub Jelinek
  2013-03-19 18:05   ` Tobias Burnus
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2013-03-19 17:24 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc patches

On Tue, Mar 19, 2013 at 04:24:04PM +0100, Tobias Burnus wrote:
> 2013-03-19  Tobias Burnus  <burnus@net-b.de>
> 
> 	* env.c (handle_omp_display_env): New function.
> 	(initialize_env): Use it.
> 
> diff --git a/libgomp/env.c b/libgomp/env.c
> index 65cbba8..e228bd9 100644
> --- a/libgomp/env.c
> +++ b/libgomp/env.c
> @@ -29,6 +29,8 @@
>  #include "libgomp_f.h"
>  #include <ctype.h>
>  #include <stdlib.h>
> +#include <stdio.h>
> +#include <inttypes.h>	/* For PRIu64.  */

stdio.h is fine, but inttypes.h needs to be
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
for portability (libgomp/configure already checks for that).

Guess this then needs to be guarded with
#ifdef HAVE_INTTYPES_H

> +      fprintf (stderr, "  GOMP_SPINCOUNT = '%"PRIu64"'\n",
> +	       (uint64_t) gomp_spin_count_var);

and if not defined, use %ld with (unsigned long) cast instead.

	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gomp 4.0] Handle OMP_DISPLAY_ENV
  2013-03-19 17:24 ` Jakub Jelinek
@ 2013-03-19 18:05   ` Tobias Burnus
  2013-03-19 18:09     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Tobias Burnus @ 2013-03-19 18:05 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc patches

[-- Attachment #1: Type: text/plain, Size: 508 bytes --]

Jakub Jelinek wrote:
>> +#include <stdio.h>
>> +#include <inttypes.h>	/* For PRIu64.  */
>
> stdio.h is fine, but inttypes.h needs to be
> #ifdef HAVE_INTTYPES_H
> # include <inttypes.h>
> #endif
> for portability (libgomp/configure already checks for that).


Good point. Attached the updated patch.

I assume, you will create the gomp-4_0-branch when gcc.gnu.org is fully 
operational. Additionally, I presume, the change-log information should 
go to the file ChangeLog.gomp and not to ChangeLog.

Tobias

[-- Attachment #2: gomp4-display-env-v2.diff --]
[-- Type: text/x-patch, Size: 4014 bytes --]

2013-03-19  Tobias Burnus  <burnus@net-b.de>

	* env.c (handle_omp_display_env): New function.
	(initialize_env): Use it.

diff --git a/libgomp/env.c b/libgomp/env.c
index 65cbba8..5cd1164 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -29,6 +29,10 @@
 #include "libgomp_f.h"
 #include <ctype.h>
 #include <stdlib.h>
+#include <stdio.h>
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>	/* For PRIu64.  */
+#endif
 #ifdef STRING_WITH_STRINGS
 # include <string.h>
 # include <strings.h>
@@ -565,6 +569,122 @@ parse_affinity (void)
   return false;
 }
 
+
+static void
+handle_omp_display_env (bool proc_bind, unsigned long stacksize,
+			int wait_policy)
+{
+  const char *env;
+  bool display = false;
+  bool verbose = false;
+  int i;
+
+  env = getenv ("OMP_DISPLAY_ENV");
+  if (env == NULL)
+    return;
+
+  while (isspace ((unsigned char) *env))
+    ++env;
+  if (strncasecmp (env, "true", 4) == 0)
+    {
+      env += 4;
+    }
+  else if (strncasecmp (env, "false", 5) == 0)
+    {
+      display = false;
+      env += 5;
+    }
+  else if (strncasecmp (env, "verbose", 7) == 0)
+    {
+      display = true;
+      verbose = true;
+      env += 7;
+    }
+  else
+    env = "X";
+  while (isspace ((unsigned char) *env))
+    ++env;
+  if (*env != '\0')
+    gomp_error ("Invalid value for environment variable OMP_DISPLAY_ENV");
+
+  if (!display)
+    return;
+
+  fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr);
+
+  fputs ("  _OPENMP = '201107'\n", stderr);
+  fprintf (stderr, "  OMP_DYNAMIC = '%s'\n",
+	   gomp_global_icv.dyn_var ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_NESTED = '%s'\n",
+	   gomp_global_icv.nest_var ? "TRUE" : "FALSE");
+
+  fprintf (stderr, "  OMP_NUM_THREADS = '%lu", gomp_global_icv.nthreads_var);
+  for (i = 1; i < gomp_nthreads_var_list_len; i++)
+    fprintf (stderr, ",%lu", gomp_nthreads_var_list[i]);
+  fputs ("'\n", stderr);
+
+  fprintf (stderr, "  OMP_SCHEDULE = '");
+  switch (gomp_global_icv.run_sched_var)
+    {
+    case GFS_RUNTIME:
+      fputs ("RUNTIME", stderr);
+      break;
+    case GFS_STATIC:
+      fputs ("STATIC", stderr);
+      break;
+    case GFS_DYNAMIC:
+      fputs ("DYNAMIC", stderr);
+      break;
+    case GFS_GUIDED:
+      fputs ("GUIDED", stderr);
+      break;
+    case GFS_AUTO:
+      fputs ("AUTO", stderr);
+      break;
+    }
+  fputs ("'\n", stderr);
+
+  fprintf (stderr, "  OMP_PROC_BIND = '%s'\n",
+	   proc_bind ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_STACKSIZE = '%lu'\n", stacksize);
+
+  /* GOMP's default value is actually neither active nor passive.  */
+  fprintf (stderr, "  OMP_WAIT_POLICY = '%s'\n",
+	   wait_policy > 0 ? "ACTIVE" : "PASSIVE");
+  fprintf (stderr, "  OMP_THREAD_LIMIT = '%lu'\n",
+	   gomp_thread_limit_var);
+  fprintf (stderr, "  OMP_MAX_ACTIVE_LEVELS = '%lu'\n",
+	   gomp_max_active_levels_var);
+
+/* FIXME: Unimplemented OpenMP 4.0 environment variables.
+  fprintf (stderr, "  OMP_PLACES = ''\n");
+  fprintf (stderr, "  OMP_CANCELLATION = ''\n");
+  fprintf (stderr, "  OMP_DEFAULT_DEVICE = ''\n"); */
+
+  if (verbose)
+    {
+      fputs ("  GOMP_CPU_AFFINITY = '", stderr);
+      if (gomp_cpu_affinity_len)
+	{
+	  fprintf (stderr, "%d", gomp_cpu_affinity[0]);
+	  for (i = 1; i < gomp_cpu_affinity_len; i++)
+	    fprintf (stderr, " %d", gomp_cpu_affinity[i]);
+	}
+      fputs ("'\n", stderr);
+      fprintf (stderr, "  GOMP_STACKSIZE = '%lu'\n", stacksize);
+#ifdef HAVE_INTTYPES_H
+      fprintf (stderr, "  GOMP_SPINCOUNT = '%"PRIu64"'\n",
+	       (uint64_t) gomp_spin_count_var);
+#else
+      fprintf (stderr, "  GOMP_SPINCOUNT = '%lu'\n",
+	       (unsigned long) gomp_spin_count_var);
+#endif
+    }
+
+  fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr);
+}
+
+
 static void __attribute__((constructor))
 initialize_env (void)
 {
@@ -645,6 +765,8 @@ initialize_env (void)
       if (err != 0)
 	gomp_error ("Stack size change failed: %s", strerror (err));
     }
+
+  handle_omp_display_env (bind_var, stacksize, wait_policy);
 }
 
 \f

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gomp 4.0] Handle OMP_DISPLAY_ENV
  2013-03-19 18:05   ` Tobias Burnus
@ 2013-03-19 18:09     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2013-03-19 18:09 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc patches

On Tue, Mar 19, 2013 at 07:05:12PM +0100, Tobias Burnus wrote:
> I assume, you will create the gomp-4_0-branch when gcc.gnu.org is
> fully operational. Additionally, I presume, the change-log
> information should go to the file ChangeLog.gomp and not to
> ChangeLog.

Yes and yes.

> 2013-03-19  Tobias Burnus  <burnus@net-b.de>
> 
> 	* env.c (handle_omp_display_env): New function.
> 	(initialize_env): Use it.

Ok, thanks.

	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-19 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-19 15:24 [gomp 4.0] Handle OMP_DISPLAY_ENV Tobias Burnus
2013-03-19 17:24 ` Jakub Jelinek
2013-03-19 18:05   ` Tobias Burnus
2013-03-19 18:09     ` Jakub Jelinek

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).