c++ - Enable/disable OpenMP locally at runtime -


is possible enable or disable openmp parallelisation @ runtime? have code should run in parallel under circumstances , not in parallel under different circumstances. @ same time, there other computations in other threads use openmp , should run in parallel. there way tell openmp not parallelise in current thread? know of omp_set_num_threads, assume globally sets number of threads openmp uses.

an alternative can use add if condition #pragma omp constructs. these skip invocation openmp runtime calls derived pragmas whenever condition false.

consider following program uses conditionals based on variables t , f (respectively true , false):

#include <omp.h> #include <stdio.h>  int main (void) {     int t = (0 == 0); // true value     int f = (1 == 0); // false value      #pragma omp parallel if (f)     { printf ("false: thread %d\n", omp_get_thread_num()); }      #pragma omp parallel if (t)     { printf ("true : thread %d\n", omp_get_thread_num()); }      return 0; } 

its output is:

$ omp_num_threads=4 ./test false: thread 0 true : thread 0 true : thread 1 true : thread 3 true : thread 2 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -