Take the 2-minute tour ×

I'm on Ubuntu 10.04, gcc version 4.4.3. I'm compiling c++ code with omp.h and a g++ parameter -fopenmp. Most of the time everything works as expected. I have quad-core with hyper-threading, so virtually 8 cores.

Randomly, when I run my software (and watch system monitor) all 8 cores woof up to 100%, fans kick in, all that good deal. Within half a second all cores but 1 shut down to inactive, and one remains working.

At this time if I cancel my program (just plain Ctrl+C) and restart it - it works as expected, all cores keep working at 100%.

Here are snippets of code in case it's useful:

28 #include <time.h>
29 #include <omp.h>
30 #include <string>
713 #ifdef _OPENMP
714         if(omp_get_dynamic())
715                 omp_set_dynamic(1);
716 #endif
718 #pragma omp parallel
719         {
720 #pragma omp for schedule(dynamic) private(node)
721                 for (int c = 0; c < buffer->GetCount(); c++) {
... initialize objects pointers etc
724 #pragma omp critical(BUFFER_LOOKUP)
725                         {
... perform chunk of code that is a choke
734                         }
share|improve this question
Take a look at this viva64.com/en/a/0054 openmp troubleshooting guide –  Martin Beckett Mar 10 '11 at 19:55
add comment

1 Answer

up vote 1 down vote accepted

From the omp_set_dynamic(n) maual page: n ... 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

Try to set the number of threads you want with a #pragma omp parallel num_threads(n) turning of the omp_set_dynamyc.

share|improve this answer
Good question. Why did you do omp_set_dynamic(1)? –  ejd Mar 11 '11 at 2:00
Because I don't know a priori how many theads I will have. I want it to utilize all available cores on whatever computer it's run –  Mikhail Mar 11 '11 at 2:28
Then you have it set incorrectly. You should be checking to see if omp_get_dynamic is "true" and if it is, then do omp_set_dynamic(0) - i.e., set it to "false". Your example above says that if it is "true" then set it to "true". You do not want the run-time to set it unless you know what it is going to set it to. –  ejd Mar 11 '11 at 3:29
Use int ncores=omp_gen_num_procs(); to know how many cores you have. Then if you really want dynamic thread num (why ?) omp_set_dynamic(ncores); I normally prefer to specify how many threads num_threads directive or omp_set_num_threads(ncores); function. –  GBBL Mar 12 '11 at 21:49
add comment

Your Answer


