Declaring a different nested number of threads for two separate tasks (OpenMP)
<p>I am writing a parallel code that is exploiting some parallelism at an outer level.  Essentially there are two separate subroutines (very expensive) that may be executed concurrently.  This is a large code, and as such, within each subroutine there are other calls as well as many omp parallel/do regions.  So to execute my two subroutines I want to make use of nested parallelism, so that they can both be called in the outer region as such:</p>

<pre><code>!$omp parallel

    !$omp single
        ! Do the first expensive task (contains more omp parallel regions)
    !$omp end single nowait

    !$omp single
        ! Do the second expensive task (contains more omp parallel regions)
    !$omp end single nowait

!$omp end parallel
</code></pre>

<p>If both of these expensive tasks took an equal amount of time I would not have a problem.  But during the simulation, at each time step, the amount that each has to do changes.  So doing an environment variable for setting the nested number of threads like <code>export OMP_NUM_THREADS=16,8</code> where I have 16 in the first level of parallelism and 8 in the nested regions (inside the two expensive subroutines) does not work well.  I have a scheme already to distribute the correct number of threads to their respective task,  I just don't know how to set different numbers of threads for the nested level in the respective subroutines.  Of course I could go into each expensive subroutine and all subroutines within those and actually hardcode the number of threads that I would like, but like I mentioned this is a very large code and that is the ugly solution.  I would much rather do this in an environment variable type of way.  There is no information on this subject online.  Does anyone out there have a clue how one could do this?</p>

<p>Thanks in advance.</p>