<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic omp_in_parallel() problem in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773783#M165</link>
    <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1313590825815="53" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=334239" href="https://community.intel.com/en-us/profile/334239/" class="basic"&gt;Clay Breshears (Intel)&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;I took a look at the OpenMP Specification 3.0 and found this explanation of the omp_in_parallel() function:&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;&lt;EM&gt;The omp_in_parallel routine returns true if the call to the routine is enclosed by an &lt;STRONG&gt;active parallel region&lt;/STRONG&gt;; otherwise, it returns false.&lt;BR /&gt;...&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OpenMP Specfication 3.1 contains the following definition of the &lt;STRONG&gt;active parallel region&lt;/STRONG&gt;:&lt;BR /&gt;"&lt;EM&gt;parallel region that is executed by a team consisting of &lt;STRONG&gt;more than one&lt;/STRONG&gt; thread&lt;/EM&gt;".&lt;BR /&gt;So, in the example omp_in_parallel() is called from &lt;STRONG&gt;non-&lt;/STRONG&gt;active parallel region and the result is correct.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2011 14:30:11 GMT</pubDate>
    <dc:creator>Olga_M_Intel</dc:creator>
    <dc:date>2011-08-17T14:30:11Z</dc:date>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773781#M163</link>
      <description>Hi all,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;i'm using Intel 11.1 with a simple openmp code. i've noted that omp_in_parallel returns 0 if i'm using just one thread:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;[cpp]int in_parallel;


#pragma omp parallel num_threads(1)
{

in_parallel=omp_in_parallel();
printf(" in_parallel: %d \n", in_parallel);

}


[/cpp]&lt;/PRE&gt; Why? I'm using one thread, but i'm in a parallel region!&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Thanks.&lt;/DIV&gt;</description>
      <pubDate>Tue, 09 Aug 2011 10:53:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773781#M163</guid>
      <dc:creator>unrue</dc:creator>
      <dc:date>2011-08-09T10:53:22Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773782#M164</link>
      <description>I took a look at the OpenMP Specification 3.0 and found this explanation of the omp_in_parallel() function:&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;&lt;EM&gt;The omp_in_parallel routine returns true if the call to the routine is enclosed by an active parallel region; otherwise, it returns false.&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;No mention about the number of threads executing that parallel region.Your source code does have the call enclosed within a parallel region. &lt;BR /&gt;&lt;BR /&gt;I tried my own test code with parallel regions usingthe default number of threads, 7 threads, and 1 thread. I also put a call to omp_in_parallel outside a parallel region. All results were as expected except the region with one thread.It reported FALSE from omp_in_parallel(). This is obviously a bug in the compiler. I'll submit a bug report.&lt;BR /&gt;&lt;BR /&gt;(I can only guess that the number of threads are used to determine this return value. It must have been thought that no one would use a parallel region with one thread and need to know if the code was executing from a parallel region.)&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2011 14:27:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773782#M164</guid>
      <dc:creator>ClayB</dc:creator>
      <dc:date>2011-08-11T14:27:52Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773783#M165</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1313590825815="53" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=334239" href="https://community.intel.com/en-us/profile/334239/" class="basic"&gt;Clay Breshears (Intel)&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;I took a look at the OpenMP Specification 3.0 and found this explanation of the omp_in_parallel() function:&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;&lt;EM&gt;The omp_in_parallel routine returns true if the call to the routine is enclosed by an &lt;STRONG&gt;active parallel region&lt;/STRONG&gt;; otherwise, it returns false.&lt;BR /&gt;...&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OpenMP Specfication 3.1 contains the following definition of the &lt;STRONG&gt;active parallel region&lt;/STRONG&gt;:&lt;BR /&gt;"&lt;EM&gt;parallel region that is executed by a team consisting of &lt;STRONG&gt;more than one&lt;/STRONG&gt; thread&lt;/EM&gt;".&lt;BR /&gt;So, in the example omp_in_parallel() is called from &lt;STRONG&gt;non-&lt;/STRONG&gt;active parallel region and the result is correct.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2011 14:30:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773783#M165</guid>
      <dc:creator>Olga_M_Intel</dc:creator>
      <dc:date>2011-08-17T14:30:11Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773784#M166</link>
      <description>Yep. The definition of an "active parallel region" appears earlier in the spec (1.2.2?). This interpretation is supported by the Intel compiler version 12.0 update #5, and g++ 4.6.0.&lt;BR /&gt;&lt;BR /&gt;Even so, this seems an odd way to define active vs. inactive since the programmer can set a region to be executed by a single thread (based on work available) or multiple threads. Also, what happens if there should be a call to omp_in_parallel() from a master region? There would only be one thread executing the call, but there might be more threads running in the overall parallel region.&lt;BR /&gt;&lt;BR /&gt;Maybe more to the point would be if nested parallelism resulted in a nested region running only a single thread in the team. Would that be an active or inactive parallel region?&lt;BR /&gt;&lt;BR /&gt;Maybe a better function would be omp_in_active() with this functionality and omp_in_parallel() to return true if the call is made from an executing parallel region regardles of the number of threads?</description>
      <pubDate>Wed, 17 Aug 2011 20:03:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773784#M166</guid>
      <dc:creator>ClayB</dc:creator>
      <dc:date>2011-08-17T20:03:44Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773785#M167</link>
      <description>IMHO if a user declares a parallel region, regardless of number of threads, the in parallel test should report true. Reason being is you may be in nested regions and/or using the OpenMP 3.n task sets (one thread per task). These tasks may be invoked within a parallel region. Therefore imho, the number of members in a team is not a controlling factor as if you are in a parallel region or not. Also consider dynamic scheduling where the number of threads that actually execute the code (possibly 1) is not necessarily the anticipated number of threads.&lt;BR /&gt;&lt;BR /&gt;As an alternative to calling a omp_in_parallel() you can call omp_get_num_threads() and if the return is .le. 1 then you are either outside parallel regions or in a region with but one thread in the team. Caution though since other teams may be running and you will not necessarily have exclusive use of all resources.&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Wed, 17 Aug 2011 20:44:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773785#M167</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2011-08-17T20:44:10Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773786#M168</link>
      <description>Do you know other way to have inside or not parallel region information not using OpenMP directives?&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;With ppid for example? Or others posix threads routines.&lt;/DIV&gt;</description>
      <pubDate>Mon, 22 Aug 2011 16:30:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773786#M168</guid>
      <dc:creator>unrue</dc:creator>
      <dc:date>2011-08-22T16:30:55Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773787#M169</link>
      <description>Well,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I found the solution:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;simply, I used omp_get_level(). By definition, it works with active and inatcive parallel region. So:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;- if omp_get_num_threads=1 andomp_get_level()=0, I'm in a serial region.&lt;/DIV&gt;&lt;DIV&gt;- ifomp_get_num_threads=1 andomp_get_level()=1 I'm in a parallel region with only one thread.&lt;/DIV&gt;&lt;DIV&gt;- ifomp_in_parallel()=1 I'm in a parallel region with more than one thread.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;It works well and it's portable.&lt;/DIV&gt;</description>
      <pubDate>Tue, 23 Aug 2011 08:37:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773787#M169</guid>
      <dc:creator>unrue</dc:creator>
      <dc:date>2011-08-23T08:37:13Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773788#M170</link>
      <description>unrue: please, could you write the final code with your solution?&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;thanks for all.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;jam&lt;/DIV&gt;</description>
      <pubDate>Sat, 03 Sep 2011 13:25:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773788#M170</guid>
      <dc:creator>jose-jesus-ambriz-me</dc:creator>
      <dc:date>2011-09-03T13:25:34Z</dc:date>
    </item>
    <item>
      <title>omp_in_parallel() problem</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773789#M171</link>
      <description>This is my solution:&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;[cpp]int my_omp_in_parallel(){

        int result = 0;

        // serial region
        if( ((omp_get_num_threads()==1)&amp;amp;&amp;amp;( omp_get_level()==0)))
                result = 0;

        // parallel region with one thread
        if( (omp_get_num_threads()==1)&amp;amp;&amp;amp;( omp_get_level()==1) )
                result = 1;

        // parallel region with more than one thread
        if( omp_in_parallel()==1 )
                result = 1;

        return result;

}
[/cpp]&lt;/PRE&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;But it works only with OpenMP 3.0, because omp_get_levels() is undefined in OpenMP 2.5.&lt;/DIV&gt;</description>
      <pubDate>Sat, 03 Sep 2011 13:55:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/omp-in-parallel-problem/m-p/773789#M171</guid>
      <dc:creator>unrue</dc:creator>
      <dc:date>2011-09-03T13:55:36Z</dc:date>
    </item>
  </channel>
</rss>

