开发者

openmp randomly uses only one core

开发者 https://www.devze.com 2023-02-16 06:05 出处:网络
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 expecte开发者_StackOverflow中文版d. I have quad-core with

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 expecte开发者_StackOverflow中文版d. 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
717 
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                         }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消