共用方式為


omp_set_dynamic

 

Indicates that the number of threads available in subsequent parallel region can be adjusted by the run time.

Syntax

void omp_set_dynamic(  
   int val  
);  

Remarks

where,

val
A value that indicates if the number of threads available in subsequent parallel region can be adjusted by the runtime. If nonzero, the runtime can adjust the number of threads, if zero, the runtime will not dynamically adjust the number of threads.

Remarks

The number of threads will never exceed the value set by omp_set_num_threads or by OMP_NUM_THREADS.

Use omp_get_dynamic to display the current setting of omp_set_dynamic.

The setting for omp_set_dynamic will override the setting of the OMP_DYNAMIC environment variable.

For more information, see 3.1.7 omp_set_dynamic Function.

Example

// omp_set_dynamic.cpp  
// compile with: /openmp  
#include <stdio.h>  
#include <omp.h>  
  
int main()   
{  
    omp_set_dynamic(9);  
    omp_set_num_threads(4);  
    printf_s("%d\n", omp_get_dynamic( ));  
    #pragma omp parallel  
        #pragma omp master  
        {  
            printf_s("%d\n", omp_get_dynamic( ));  
        }  
}  
1  
1  

See Also

Functions