%\pagebreak
\section{\kcode{omp_pause_resource} and \\
  \kcode{omp_pause_resource_all} Routines}
\label{sec:pause_resource}
\index{routines!omp_pause_resource@\kcode{omp_pause_resource}}
\index{omp_pause_resource routine@\kcode{omp_pause_resource} routine}
\index{routines!omp_get_max_threads@\kcode{omp_get_max_threads}}
\index{omp_get_max_threads routine@\kcode{omp_get_max_threadsi} routine}
\index{routines!omp_get_initial_device@\kcode{omp_get_initial_device}}
\index{omp_get_initial_device routine@\kcode{omp_get_initial_device} routine}

Sometimes, it is necessary to relinquish resources created or allocated
for the OpenMP runtime environment to avoid interference with subsequent
actions as illustrated by the following example.  In the beginning 
either a call to the \kcode{omp_get_max_threads} routine 
or the subsequent \kcode{parallel} construct may trigger resource allocation
by the OpenMP runtime, which may cause unexpected side effects 
for the subsequent \ucode{fork} call.
It is desirable to relinquish OpenMP resources allocated before 
the fork by using the \kcode{omp_pause_resource} routine for a given
device, in this case the host device.  The host device number is returned by 
the \kcode{omp_get_initial_device} routine.
The \kcode{omp_pause_hard} value is used here to free as many
OpenMP resources as possible.
After the fork, the child process will initialize its OpenMP runtime
environment when encountering the \kcode{parallel} construct.

\cexample[5.0]{pause_resource}{1}
\pagebreak

\index{routines!omp_pause_resource_all@\kcode{omp_pause_resource_all}}
\index{omp_pause_resource_all routine@\kcode{omp_pause_resource_all} routine}
The following example illustrates a different use case. 
After executing the first parallel code (parallel region 1), 
the \ucode{relinquish} program switches to executing an external parallel program
(called \ucode{subprogram}, which is compiled from \example{pause_resource.2b}).  
In order to make resources available for the external
subprogram, \ucode{relinquish} calls \kcode{omp_pause_resource_all}
to relinquish OpenMP resources used by the current program before
calling \ucode{execute_command_line} to execute \ucode{subprogram}.
The \kcode{omp_pause_soft} value is used here to allow subsequent
OpenMP regions (parallel region 2) to restart more quickly.

\ffreeexample[5.0]{pause_resource}{2a}
\ffreeexample{pause_resource}{2b}
