<?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_SET_NUM_THREADS in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959197#M5286</link>
    <description>&lt;DIV&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;PRE&gt;! Running on system with 4 processors

    iMaxThreads = OMP_GET_MAX_THREADS()	     ! runtime environment returns 4
    call    OMP_SET_NUM_THREADS(iMaxThreads) ! set to 4 threads

!$OMP PARALLEL DO PRIVATE(I) SHARED COUNT
DO I=1,COUNT
	CALL FOO2(SOMETHING(I))
	CALL FOO3(OTHERTHING(I))
END DO
!$OMP END PARALLEL

...

SUBROUTINE FOO2(X)
  call    OMP_SET_NUM_THREADS(2) ! set to 2 threads
	(race window here)
!$OMP PARALLEL SECTIONS
!$OMP SECTION
  block1
!$OMP SECTION
  block2
!$OMP PARALLEL SECTIONS
END SUBROUTINE FOO2


SUBROUTINE FOO3(X)
  call    OMP_SET_NUM_THREADS(3) ! set to 3 threads
	(race window here)
!$OMP PARALLEL SECTIONS
!$OMP SECTION
  block1
!$OMP SECTION
  block2
!$OMP SECTION
  block3
!$OMP PARALLEL SECTIONS
END SUBROUTINE FOO3

&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Does the call to OMP_SET_NUM_THREADS affect only the thread that issues the call (thread context variable) or are all threads affected (global variable)?&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Jim Dempsey&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 08 Dec 2005 06:21:15 GMT</pubDate>
    <dc:creator>jim_dempsey</dc:creator>
    <dc:date>2005-12-08T06:21:15Z</dc:date>
    <item>
      <title>OMP_SET_NUM_THREADS</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959197#M5286</link>
      <description>&lt;DIV&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;PRE&gt;! Running on system with 4 processors

    iMaxThreads = OMP_GET_MAX_THREADS()	     ! runtime environment returns 4
    call    OMP_SET_NUM_THREADS(iMaxThreads) ! set to 4 threads

!$OMP PARALLEL DO PRIVATE(I) SHARED COUNT
DO I=1,COUNT
	CALL FOO2(SOMETHING(I))
	CALL FOO3(OTHERTHING(I))
END DO
!$OMP END PARALLEL

...

SUBROUTINE FOO2(X)
  call    OMP_SET_NUM_THREADS(2) ! set to 2 threads
	(race window here)
!$OMP PARALLEL SECTIONS
!$OMP SECTION
  block1
!$OMP SECTION
  block2
!$OMP PARALLEL SECTIONS
END SUBROUTINE FOO2


SUBROUTINE FOO3(X)
  call    OMP_SET_NUM_THREADS(3) ! set to 3 threads
	(race window here)
!$OMP PARALLEL SECTIONS
!$OMP SECTION
  block1
!$OMP SECTION
  block2
!$OMP SECTION
  block3
!$OMP PARALLEL SECTIONS
END SUBROUTINE FOO3

&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Does the call to OMP_SET_NUM_THREADS affect only the thread that issues the call (thread context variable) or are all threads affected (global variable)?&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Jim Dempsey&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 08 Dec 2005 06:21:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959197#M5286</guid>
      <dc:creator>jim_dempsey</dc:creator>
      <dc:date>2005-12-08T06:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: OMP_SET_NUM_THREADS</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959198#M5287</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;
&lt;P&gt;The OpenMP 2.5 specification isn't clear on this question. In the Intel OpenMP implementation,the call to &lt;FONT face="Courier New"&gt;OMP_SET_NUM_THREADS&lt;/FONT&gt; should only affect the calling thread. In other OpenMP implementations, the calls to &lt;FONT face="Courier New"&gt;OMP_SET_NUM_THREADS&lt;/FONT&gt; inside the first parallel region may createa race condition. Putting a&lt;FONT face="Courier New"&gt;num_threads&lt;/FONT&gt; clause on the &lt;FONT face="Courier New"&gt;parallel&lt;/FONT&gt; directives is probably a better, more portable option.&lt;/P&gt;
&lt;P&gt;Henry&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2005 08:00:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959198#M5287</guid>
      <dc:creator>Henry_G_Intel</dc:creator>
      <dc:date>2005-12-15T08:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: OMP_SET_NUM_THREADS</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959199#M5288</link>
      <description>&lt;P&gt;Number of threads is not a clause available in Fortran.&lt;/P&gt;
&lt;P&gt;Also, what is not known to me at this time is when in the first-level parallel section a team member requests n threads for then next parallel section it enters, if the Windows threads created on the 1st entry into the second level parallel section are persistent after exit of the section (on behalf of the calling thread) and then the same Windows threads are reused as the same sub-team member number thread upon subsequent re-entry into the second level by the samecalling thread. (that is a mouthful). Example&lt;/P&gt;
&lt;P&gt;Thread.0/ handle1 - Main program thread&lt;/P&gt;
&lt;P&gt;- First PARALLEL level (assume 3 threads)&lt;/P&gt;
&lt;P&gt;Thread.0.0 / handle 1 - Same Window handle that entered this section&lt;/P&gt;
&lt;P&gt;Thread.0.1 / handle 2 - New Windows handle&lt;/P&gt;
&lt;P&gt;Thread.0.2 / handle 3 - New Windows handle&lt;/P&gt;
&lt;P&gt;--- each of the above 3 team members (threads) enter next level (assume each requests 2 threads and 2 are available)&lt;/P&gt;
&lt;P&gt;Thread.0.0.0 / handle 1- &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 17 Dec 2005 02:00:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959199#M5288</guid>
      <dc:creator>jim_dempsey</dc:creator>
      <dc:date>2005-12-17T02:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: OMP_SET_NUM_THREADS</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959200#M5289</link>
      <description>&lt;P&gt;Will rewrite and post - Damb Reply to Message is hosing me -grrr...&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 17 Dec 2005 02:01:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959200#M5289</guid>
      <dc:creator>jim_dempsey</dc:creator>
      <dc:date>2005-12-17T02:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: OMP_SET_NUM_THREADS</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959201#M5290</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;Thread.0 / handle1          - Main program thread

- First PARALLEL level (assume 3 threads)

Thread.0.0 / handle 1      - Same Window handle that entered this section
Thread.0.1 / handle 2     - New Windows handle
Thread.0.2 / handle 3     - New Windows handle

- Second Parallel level. Each of the above 3 team members (threads) enter 2nd level (assume each requests 2 threads and 2 are available and given)

Thread.0.0.0 / handle 1	Team for first thread in level above 
Thread.0.0.1 / handle 4

Thread.0.1.0 / handle 2	Team for second thread in level above
Thread.0.1.1 / handle 5

Thread.0.2.0 / handle 3	Team for third thread in level above
Thread.0.2.1 / handle 6

- End Second Parallel level

- End First Parallel level

Not that the following makes programming sense

- Enter different code for new first parallel level (assume 2 threads)

Thread.0.0 / handle 1      - Same Window handle that entered this section
Thread.0.1 / handle 2     - Reuse of Windows handle
(Thread.0.1 / handle 3 not used but Windows handle 3 reserved an not reused below)

- Second Parallel level. Each of the above 2 team members (threads) enter 2nd level (assume each requests 3 threads and 3 are available and given)


Thread.0.0.0 / handle 1	Team for first thread in level above 
Thread.0.0.1 / handle 4 Reuse of same Windows handle
Thread.0.0.2 / handle 7 New Windows handle for 1st use

Thread.0.1.0 / handle 2	Team for second thread in level above
Thread.0.1.1 / handle 5 Reuse of same Windows handle
Thread.0.1.2 / handle 8 New Windows handle for 1st use

- End Second Parallel level
- End First Parallel level&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;As to why this would make a difference know if the Windows (Linux) thread handles, once allocated, remain bound to the nested level and team member number.&lt;/P&gt;
&lt;P&gt;1) There is operating system overhead to create and destroy threads.&lt;/P&gt;
&lt;P&gt;2) Resources that are thread specific will persists across entries and reentries of level&lt;/P&gt;
&lt;P&gt;3) The application can have a one time resource assessment and then set Windows thread Affinity to a particular processor or group of processors.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Message Edited by hagabb on &lt;SPAN class="date_text"&gt;12-16-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:25 PM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2005 02:28:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959201#M5290</guid>
      <dc:creator>jim_dempsey</dc:creator>
      <dc:date>2005-12-17T02:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: OMP_SET_NUM_THREADS</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959202#M5291</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Hi Jim,&lt;/P&gt;
&lt;P&gt;According to the OpenMP 2.5 API, the &lt;FONT face="Courier New"&gt;num_threads&lt;/FONT&gt; clause is available in Fortran. The &lt;A href="http://www.intel.com/cd/software/products/asmo-na/eng/compilers/219714.htm" target="_blank"&gt;Intel 9.0 Fortran compiler&lt;/A&gt; supports OpenMP 2.5 so you should not have any trouble using the &lt;FONT face="Courier New"&gt;num_threads&lt;/FONT&gt; clause on your parallel directives.&lt;/P&gt;
&lt;P&gt;The Intel OpenMP implementationuses a thread pool to avoid the overhead of repeatedly creating and destroying threads. Otherwise, putting an OpenMP parallel region inside of a loop, for example, would incur significant system overhead every time the parallel region was entered (thread creation) and exited (thread destruction). The Intel OpenMP implementation simply reuses threads and adds more threads if needed. However, this would make it difficult toassociate Windows &lt;FONT face="Courier New"&gt;HANDLE&lt;/FONT&gt;'s with a particular OpenMP thread team.&lt;/P&gt;
&lt;P&gt;Henry&lt;/P&gt;&lt;P&gt;Message Edited by hagabb on &lt;SPAN class="date_text"&gt;12-16-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:02 PM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2005 04:46:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/OMP-SET-NUM-THREADS/m-p/959202#M5291</guid>
      <dc:creator>Henry_G_Intel</dc:creator>
      <dc:date>2005-12-17T04:46:52Z</dc:date>
    </item>
  </channel>
</rss>

