]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Add support for the omp_get_supported_active_levels runtime library routine
authorKwok Cheung Yeung <kcy@codesourcery.com>
Wed, 7 Oct 2020 16:34:32 +0000 (09:34 -0700)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Wed, 11 Nov 2020 20:57:43 +0000 (12:57 -0800)
This patch implements the omp_get_supported_active_levels runtime routine
from the OpenMP 5.0 specification, which returns the maximum number of
active nested parallel regions supported by this implementation.  The
current maximum (set using the omp_set_max_active_levels routine or the
OMP_MAX_ACTIVE_LEVELS environment variable) cannot exceed this number.

This is a backport from mainline (commits
8949b985dbaf07d433bd57d2883e1e5414f20e75 and
445567b22a3c535be0b1861b393e9a0b050f2b1e).

2020-10-13  Kwok Cheung Yeung  <kcy@codesourcery.com>

libgomp/
* env.c (gomp_max_active_levels_var): Initialize to
gomp_supported_active_levels.
(initialize_env): Limit gomp_max_active_levels_var to be at most
equal to gomp_supported_active_levels.
* fortran.c (omp_get_supported_active_levels): Add ialias_redirect.
(omp_get_supported_active_levels_): New.
* icv.c (omp_set_max_active_levels): Limit gomp_max_active_levels_var
to at most equal to gomp_supported_active_levels.
(omp_get_supported_active_levels): New.
* libgomp.h (gomp_supported_active_levels): New.
* libgomp.map (OMP_5.0.1): Add omp_get_supported_active_levels and
omp_get_supported_active_levels_.
* libgomp.texi (omp_get_max_active_levels): Modify description.
(omp_get_supported_active_levels): New.
(omp_set_max_active_levels): Update.  Add reference to
omp_get_supported_active_levels.
* omp.h.in (omp_get_supported_active_levels): New.
* omp_lib.f90.in (omp_get_supported_active_levels): New.
* omp_lib.h.in (omp_get_supported_active_levels): New.
* testsuite/libgomp.c/lib-2.c (main): Check omp_get_max_active_levels
against omp_get_supported_active_levels.
* testsuite/libgomp.fortran/lib4.f90 (lib4): Likewise.

12 files changed:
libgomp/ChangeLog.omp
libgomp/env.c
libgomp/fortran.c
libgomp/icv.c
libgomp/libgomp.h
libgomp/libgomp.map
libgomp/libgomp.texi
libgomp/omp.h.in
libgomp/omp_lib.f90.in
libgomp/omp_lib.h.in
libgomp/testsuite/libgomp.c/lib-2.c
libgomp/testsuite/libgomp.fortran/lib4.f90

index 88428fb412c7e68675afe2c6b32486aebabdba9f..f4963e85170aecd0a6d7e60eccd042003050a7ef 100644 (file)
@@ -1,3 +1,31 @@
+2020-11-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       Backport from mainline
+       2020-10-13  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * env.c (gomp_max_active_levels_var): Initialize to
+       gomp_supported_active_levels.
+       (initialize_env): Limit gomp_max_active_levels_var to be at most
+       equal to gomp_supported_active_levels.
+       * fortran.c (omp_get_supported_active_levels): Add ialias_redirect.
+       (omp_get_supported_active_levels_): New.
+       * icv.c (omp_set_max_active_levels): Limit gomp_max_active_levels_var
+       to at most equal to gomp_supported_active_levels.
+       (omp_get_supported_active_levels): New.
+       * libgomp.h (gomp_supported_active_levels): New.
+       * libgomp.map (OMP_5.0.1): Add omp_get_supported_active_levels and
+       omp_get_supported_active_levels_.
+       * libgomp.texi (omp_get_max_active_levels): Modify description.
+       (omp_get_supported_active_levels): New.
+       (omp_set_max_active_levels): Update.  Add reference to
+       omp_get_supported_active_levels.
+       * omp.h.in (omp_get_supported_active_levels): New.
+       * omp_lib.f90.in (omp_get_supported_active_levels): New.
+       * omp_lib.h.in (omp_get_supported_active_levels): New.
+       * testsuite/libgomp.c/lib-2.c (main): Check omp_get_max_active_levels
+       against omp_get_supported_active_levels.
+       * testsuite/libgomp.fortran/lib4.f90 (lib4): Likewise.
+
 2020-09-28  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline
index c0c4730d47c7d0b8320206bb62a60bc1f8043f2d..d730c483d7f7f33dd7523862599d1c48a8e85b61 100644 (file)
@@ -73,7 +73,7 @@ struct gomp_task_icv gomp_global_icv = {
   .target_data = NULL
 };
 
-unsigned long gomp_max_active_levels_var = INT_MAX;
+unsigned long gomp_max_active_levels_var = gomp_supported_active_levels;
 bool gomp_cancel_var = false;
 int gomp_max_task_priority_var = 0;
 #ifndef HAVE_SYNC_BUILTINS
@@ -1369,6 +1369,8 @@ initialize_env (void)
   parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var, true);
   parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var,
                       true);
+  if (gomp_max_active_levels_var > gomp_supported_active_levels)
+    gomp_max_active_levels_var = gomp_supported_active_levels;
   gomp_def_allocator = parse_allocator ();
   if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var, false))
     {
index 9d838b3b56f3ac5d62b27f748d9f08723a5da851..029dec17459412d04753f0eb10e307baede2c94b 100644 (file)
@@ -63,6 +63,7 @@ ialias_redirect (omp_get_schedule)
 ialias_redirect (omp_get_thread_limit)
 ialias_redirect (omp_set_max_active_levels)
 ialias_redirect (omp_get_max_active_levels)
+ialias_redirect (omp_get_supported_active_levels)
 ialias_redirect (omp_get_level)
 ialias_redirect (omp_get_ancestor_thread_num)
 ialias_redirect (omp_get_team_size)
@@ -417,6 +418,12 @@ omp_get_max_active_levels_ (void)
   return omp_get_max_active_levels ();
 }
 
+int32_t
+omp_get_supported_active_levels_ (void)
+{
+  return omp_get_supported_active_levels ();
+}
+
 int32_t
 omp_get_level_ (void)
 {
index 3c16abb9123595d8d5362eeeca2213b5552663db..1bb46abac438e71cc7f50db2574a91d153e0fe6b 100644 (file)
@@ -116,7 +116,12 @@ void
 omp_set_max_active_levels (int max_levels)
 {
   if (max_levels >= 0)
-    gomp_max_active_levels_var = max_levels;
+    {
+      if (max_levels <= gomp_supported_active_levels)
+       gomp_max_active_levels_var = max_levels;
+      else
+       gomp_max_active_levels_var = gomp_supported_active_levels;
+    }
 }
 
 int
@@ -125,6 +130,12 @@ omp_get_max_active_levels (void)
   return gomp_max_active_levels_var;
 }
 
+int
+omp_get_supported_active_levels (void)
+{
+  return gomp_supported_active_levels;
+}
+
 int
 omp_get_cancellation (void)
 {
@@ -227,6 +238,7 @@ ialias (omp_get_max_threads)
 ialias (omp_get_thread_limit)
 ialias (omp_set_max_active_levels)
 ialias (omp_get_max_active_levels)
+ialias (omp_get_supported_active_levels)
 ialias (omp_get_cancellation)
 ialias (omp_get_proc_bind)
 ialias (omp_get_initial_device)
index d37fcb84b0c910a8550eaf8705e047b7c6578995..20b9042e3330d538fdaff8b85316d98c11d307d8 100644 (file)
@@ -434,6 +434,8 @@ struct gomp_task_icv
   struct target_mem_desc *target_data;
 };
 
+#define gomp_supported_active_levels INT_MAX
+
 extern struct gomp_task_icv gomp_global_icv;
 #ifndef HAVE_SYNC_BUILTINS
 extern gomp_mutex_t gomp_managed_threads_lock;
index c808e810702c5cf7d03d0d54eb43d346153b9d19..c5f52f725d06b498b626c93c1c8b077f3a86fd00 100644 (file)
@@ -193,6 +193,8 @@ OMP_5.0.1 {
        omp_destroy_allocator_;
        omp_alloc;
        omp_free;
+       omp_get_supported_active_levels;
+       omp_get_supported_active_levels_;
 } OMP_5.0;
 
 GOMP_1.0 {
index a6dabaacd52c414906e909f5a603d209e53eeba2..5a9d4c8349eab0e32574b7ff07edae0169ec3014 100644 (file)
@@ -167,7 +167,7 @@ linkage, and do not throw exceptions.
 * omp_get_default_device::      Get the default device for target regions
 * omp_get_dynamic::             Dynamic teams setting
 * omp_get_level::               Number of parallel regions
-* omp_get_max_active_levels::   Maximum number of active regions
+* omp_get_max_active_levels::   Current maximum number of active regions
 * omp_get_max_task_priority::   Maximum task priority value that can be set
 * omp_get_max_threads::         Maximum number of threads of parallel region
 * omp_get_nested::              Nested parallel regions
@@ -177,6 +177,7 @@ linkage, and do not throw exceptions.
 * omp_get_num_threads::         Size of the active team
 * omp_get_proc_bind::           Whether theads may be moved between CPUs
 * omp_get_schedule::            Obtain the runtime scheduling method
+* omp_get_supported_active_levels:: Maximum number of active regions supported
 * omp_get_team_num::            Get team number
 * omp_get_team_size::           Number of threads in a team
 * omp_get_thread_limit::        Maximum number of threads
@@ -379,7 +380,7 @@ which enclose the calling call.
 
 
 @node omp_get_max_active_levels
-@section @code{omp_get_max_active_levels} -- Maximum number of active regions
+@section @code{omp_get_max_active_levels} -- Current maximum number of active regions
 @table @asis
 @item @emph{Description}:
 This function obtains the maximum allowed number of nested, active parallel regions.
@@ -638,6 +639,31 @@ set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
 @end table
 
 
+@node omp_get_supported_active_levels
+@section @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
+@table @asis
+@item @emph{Description}:
+This function returns the maximum number of nested, active parallel regions
+supported by this implementation.
+
+@item @emph{C/C++}
+@multitable @columnfractions .20 .80
+@item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
+@end multitable
+
+@item @emph{Fortran}:
+@multitable @columnfractions .20 .80
+@item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
+@end multitable
+
+@item @emph{See also}:
+@ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
+
+@item @emph{Reference}:
+@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
+@end table
+
+
 
 @node omp_get_team_num
 @section @code{omp_get_team_num} -- Get team number
@@ -877,7 +903,8 @@ adjustment of team sizes and @code{false} disables it.
 @table @asis
 @item @emph{Description}:
 This function limits the maximum allowed number of nested, active
-parallel regions.
+parallel regions.  @var{max_levels} must be less or equal to
+the value returned by @code{omp_get_supported_active_levels}.
 
 @item @emph{C/C++}
 @multitable @columnfractions .20 .80
@@ -891,7 +918,8 @@ parallel regions.
 @end multitable
 
 @item @emph{See also}:
-@ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
+@ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
+@ref{omp_get_supported_active_levels}
 
 @item @emph{Reference}:
 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
index 57af73720f1d640ba976c0faf38d7025f1baae04..a9e6c448dc3ca95fa6962e96e50aeeb887bef48e 100644 (file)
@@ -211,6 +211,7 @@ extern void omp_get_schedule (omp_sched_t *, int *) __GOMP_NOTHROW;
 extern int omp_get_thread_limit (void) __GOMP_NOTHROW;
 extern void omp_set_max_active_levels (int) __GOMP_NOTHROW;
 extern int omp_get_max_active_levels (void) __GOMP_NOTHROW;
+extern int omp_get_supported_active_levels (void) __GOMP_NOTHROW;
 extern int omp_get_level (void) __GOMP_NOTHROW;
 extern int omp_get_ancestor_thread_num (int) __GOMP_NOTHROW;
 extern int omp_get_team_size (int) __GOMP_NOTHROW;
index b22bcbaf77013559cfe1b99fc6901d75da3ded44..c7dbf384c53f74ad36012e650a2fef6523f4a1f7 100644 (file)
           end function omp_get_max_active_levels
         end interface
 
+        interface
+          function omp_get_supported_active_levels ()
+            integer (4) :: omp_get_supported_active_levels
+          end function omp_get_supported_active_levels
+        end interface
+
         interface
           function omp_get_level ()
             integer (4) :: omp_get_level
index c7d444d4a97f73d79241ccf514ed55b6cabcfcae..b06e5681334969230416c1ebb5299b8243464aa5 100644 (file)
       external omp_get_max_active_levels, omp_get_level
       external omp_get_ancestor_thread_num, omp_get_team_size
       external omp_get_active_level
+      external omp_get_supported_active_levels
       integer(4) omp_get_thread_limit, omp_get_max_active_levels
       integer(4) omp_get_level, omp_get_ancestor_thread_num
       integer(4) omp_get_team_size, omp_get_active_level
+      integer(4) omp_get_supported_active_levels
 
       external omp_in_final
       logical(4) omp_in_final
index 3a3b3f65517b636040949a3e026282713efee0b8..ea7a71904f09f30f29d9d9b86c4b5a370011f558 100644 (file)
@@ -20,6 +20,8 @@ main (void)
   omp_set_max_active_levels (6);
   if (omp_get_max_active_levels () != 6)
     abort ();
+  if (omp_get_max_active_levels () > omp_get_supported_active_levels ())
+    abort ();
 
   return 0;
 }
index d551cde35c67a210a42df4ed6b4b0665bbf51dad..5259b3bd95d5566950c57c2cf4dac6ce08fe8a06 100644 (file)
@@ -13,4 +13,6 @@ program lib4
   if (omp_get_thread_limit ().lt.0) stop 3
   call omp_set_max_active_levels (6)
   if (omp_get_max_active_levels ().ne.6) stop 4
+  if (omp_get_max_active_levels () &
+      .gt.omp_get_supported_active_levels ()) stop 5
 end program lib4