Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1694 Discussions

is it possible to set the threads dynamically depending on system configuration in openMP

is it possible to set the threads dynamically depending on system configuration in openMP.
here system configuration means dual core(or)quad core.
0 Kudos
1 Reply

normally, the OpenMP runtime automatically chooses the thread count such that all cores on your system receive one thread and the system is not overloaded. However, this does not take into account if cores are utilizied by other applications. Please note that OpenMP does not differentiate physical cores and logical cores available with Hyper Threading.

If you want to set the number of threads manually you've got these options:

  • set the environment variable OMP_NUM_THREADS to the number of threads. For example "export OMP_NUM_THREADS=16" in a Linux bash shell will set the number of thread to 16 for all OpenMP application launched through that bash shell.
  • Use the OpenMP runtime call omp_set_num_threads(n) to set the number of threads from within the application. You can use omp_get_num_procs() to determine the number of cores in your system.
  • Add a the num_threads clause to your parallel regions to explicitly specify the thread count for each parallel region individually.
To receive exactly the number of threads you have specified it is always a good idea to have as one of the first calls on your application to call omp_set_dynamic(0). Otherwise, the OpenMP runtime might choose any number of threads between 1 and what you have specified through one of the means above.

0 Kudos