Rookie HPC

Teaming

C | FORTRAN

omp_get_dynamic

Definition

The function omp_get_dynamic indicates whether dynamic adjustement is enabled. Dynamic adjustment is the feature that allows the runtime system to provide fewer threads than requested for a parallel region. In codes with recursively nested parallel regions for instance, the total number of threads to spawn may generate a high oversubscription, dynamic adjustement allows the runtime system to handle that growth. It can be enabled or disabled using the function omp_set_dynamic.

Copy

Feedback

int omp_get_dynamic();

Returned value

The dynamic adjustement state.

0
Dynamic adjustement is disabled.
<otherwise>
Dynamic adjustement is enabled.

Example

Copy

Feedback

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

/**
 * @brief Illustrates how to check the state of the dynamic adjustment.
 **/
int main(int argc, char* argv[])
{
    if(omp_get_dynamic())
    {
        printf("By default, dynamic adjustment is allowed.\n");
    }
    else
    {
        printf("By default, dynamic adjustment is not allowed.\n");
    }

    // Invert the dynamic adjustement
    omp_set_dynamic(omp_get_dynamic() ? 0 : 1);

    if(omp_get_dynamic())
    {
        printf("Dynamic adjustment is now allowed.\n");
    }
    else
    {
        printf("Dynamic adjustment is no longer allowed.\n");
    }

    return EXIT_SUCCESS;
}