Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with setting OMP_THREAD_LIMIT during runtime (c++ gcc 4.4.7)
    primarykey
    data
    text
    <p>Heluuu,</p> <p>I have a rather large program that I'm attempting to thread. So far, this has been succesful, and the basics are all working as intended.</p> <p>I now want to do some fancy work with cascading threads in nested mode. Essentially, I want the main parallel region to use any free threads in lower parallel regions.</p> <p>To detail the current system, the main parallel region starts 10 threads. I have 12 cores, so I can use 2 more threads. There is a second parallel region where some heavy computing happens, and I want the first two threads to reach this point to start a new team there, each with 2 threads. Every new entry to the lower parallel region after this will continue in serial. </p> <p>So, this should look like the following.<br> Main region: 10 threads started.<br> Lower region: 2 new threads started. </p> <p>Thread 1: 2 threads in lower region.<br> Thread 2: 2 threads in lower region.<br> Thread 3-10: 1 thread in lower region. </p> <p>Please keep in mind that these numbers are for the sake of clarity in providing a concrete description of my situation, and not the absolute and only case in which the program operates. </p> <p>The code:</p> <pre><code>main() { ... ... omp_set_num_threads(n); omp_set_dynamic(x); #pragma omp parallel { #pragma omp for for (int i = 0; i &lt; iterations; i++) { ... Compute(); ... } } } </code></pre> <p>And in Compute</p> <pre><code>bool Compute() { ... float nThreads = omp_get_thread_limit() - omp_get_num_threads(); nThreads = ceil(nThreads / omp_get_num_threads()); omp_set_num_threads((int)nThreads); #pragma omp parallel { ... #pragma omp for for (int i = 0; i &lt; nReductSize; i++) { ... } } } </code></pre> <p>Now, my problem is that setting the uppermost limit for the whole program (i.e. OMP_THREAD_LIMIT) only works from outside the program. Using </p> <pre><code>export OMP_THREAD_LIMIT=5 </code></pre> <p>from the bash command line works great. But I want to do it internally. So far, I've tried </p> <pre><code>putenv("OMP_THREAD_LIMIT=12"); setenv("OMP_THREAD_LIMIT", "12", 1); </code></pre> <p>but when I call omp_get_thread_limit() or getenv("OMP_THREAD_LIMIT") I get wacky return values. Even when I set the variable with export, calling getenv("OMP_THREAD_LIMIT"); returns 0.<br> So, I would ask for your help in this: How do I properly set OMP_THREAD_LIMIT at runtime?</p> <p>This is the main function where I set the thread defaults. It is executed well before any threading occurs:</p> <pre><code>#ifdef _OPENMP const char *name = "OMP_THREAD_LIMIT"; const char *value = "5"; int overwrite = 1; int success = setenv(name, value, overwrite); cout &lt;&lt; "Var set (0 is success): " &lt;&lt; success &lt;&lt; endl; #endif </code></pre> <p>Oh, and setenv reports success in setting the variable. </p> <p>Compiler says<br> gcc44 (GCC) 4.4.7 20120313 (Red Hat 4.4.7-1) </p> <p>Flags<br> CCFLAGS = -c -O0 -fopenmp -g -msse -msse2 -msse3 -mfpmath=sse -std=c++0x </p> <p>OpenMP version is 3.0.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload