.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
   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))
     {
 
 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)
   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)
 {
 
 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
   return gomp_max_active_levels_var;
 }
 
+int
+omp_get_supported_active_levels (void)
+{
+  return gomp_supported_active_levels;
+}
+
 int
 omp_get_cancellation (void)
 {
 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)
 
   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;
 
        omp_destroy_allocator_;
        omp_alloc;
        omp_free;
+       omp_get_supported_active_levels;
+       omp_get_supported_active_levels_;
 } OMP_5.0;
 
 GOMP_1.0 {
 
 * 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:: Maxiumum number of active levels 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
 @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
 @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
 @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.
 
 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;
 
           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
 
       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
 
   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;
 }
 
   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