# NAG FL Interfacex06ajf (set_​max_​active_​levels)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

x06ajf sets the number of nested active parallel regions.

## 2Specification

Fortran Interface
 Subroutine x06ajf ( num,
 Integer, Intent (In) :: num Integer, Intent (Inout) :: ifail
#include <nag.h>
 void x06ajf_ (const Integer *num, Integer *ifail)
The routine may be called by the names x06ajf or nagf_omp_set_max_active_levels.

## 3Description

x06ajf, for multithreaded implementations, sets the maximum number of nested active parallel regions to num.
When num is set to zero parallelism is disabled, if set to one then only the outermost parallel region is active and nested regions are inactive (i.e., no new threads are created when entering the nested parallel region and it is executed in serial.) If num is set to $n$, where $n\ge 2$ then $n$ parallel regions can be active and $n-1$ nested regions can be active.
In serial implementations of the NAG Library this routine has no effect. See the X06 Chapter Introduction for a discussion of the behaviour of these routines when called in serial.

## 4References

The OpenMP API Specification for Parallel Programming
Chapman B, Jost G and van der Pas R (2008) Using OpenMP Portable Shared Memory Parallel Programming The MIT Press

## 5Arguments

1: $\mathbf{num}$Integer Input
On entry: $n$, the number of active parallel regions allowed.
If ${\mathbf{num}}=0$
parallelism is disabled.
If ${\mathbf{num}}=1$
the outermost parallel region is active and nested regions are inactive (i.e., no new threads are created when entering the nested parallel region and it is executed in serial.)
If ${\mathbf{num}}\ge 2$
num parallel regions can be active and ${\mathbf{num}}-1$ nested regions can be active.
Constraint: ${\mathbf{num}}\ge 0$.
2: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{num}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{num}}\ge 0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

x06ajf is not threaded in any implementation.

None.

## 10Example

In this example we presume a multithreaded implementation of the NAG Library.
We first show the default behaviour for nested active parallel regions of the implementation being used. We have a counter inside a nested parallel region which is incremented by each thread and whose final value is the number of threads in the nested parallel region multiplied by the number of threads in the outer parallel region. Thus showing whether the nested region is active or not.
We then repeat the same text but call x06ajf and set ${\mathbf{num}}=2$ which enables $1$ level of nesting, which is all that is used in this example.
Finally, we call x06ajf again, this time ${\mathbf{num}}=1$ which disables nested parallel regions.
If you use a serial implementation of the NAG Library, regardless of whether the code is compiled with OpenMP or not, calling x06ajf has no effect. The appropriate result file will be included with the distribution material for your implementation.

### 10.1Program Text

Program Text (x06ajfe.f90)

None.

### 10.3Program Results

Program Results (x06ajfe.r)