Rookie HPC

Teaming

C | FORTRAN

omp_set_dynamic

Definition

The function omp_set_dynamic is one of the two ways to enable / disable dynamic adjustment. The other one is the environment variable OMP_DYNAMIC. 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. One can check if dynamic adjustment is enabled or disabled using the function omp_get_dynamic.

Copy

Feedback

void omp_set_dynamic(int state);

Parameters

state
If it evaluates to true dynamic adjustement is allowed, not allowed where appropriate.

Example

Copy

Feedback

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

/**
 * @brief Illustrates how to change 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;
}