<?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 Re: Quenstion regarding weird bug with OpenMP parallelization in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Quenstion-regarding-weird-bug-with-OpenMP-parallelization/m-p/1484921#M166321</link>
    <description>&lt;P&gt;Running through an empty (or do nothing) parallel region (that is not removed/elided by compiler optimizations will incur the overhead of starting or resuming the thread team of that parallel region. More threads, more overhead. It is only when the parallel region has sufficient parallizable code to surpass the overhead that parallelization becomes effective.&lt;/P&gt;
&lt;P&gt;Note, your parallel region (of your actual project) may contain serialized (critical) sections, which will intercede with parallization for that section of code. Some system functions have critical sections. Examples: random number generators, memory allocation/deallocation. Also note that should "Reallocation of lefthand side" result in reallocation (memory deallocation and allocation) that those statements will serialize.&lt;/P&gt;
&lt;P&gt;Without seeing your real code, I will make an assumption:&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;    REAL (KIND(0.0)), DIMENSION(Nbr_SSS,2,jmax,lmax) :: U2
    REAL (KIND(0.0)), DIMENSION(Nbr_SSS,2,jmax,lmax) :: Var1
&lt;/LI-CODE&gt;
&lt;P&gt;that your intention is to have each thread work on an individual Nbr_SSS section of the arrays.&lt;/P&gt;
&lt;P&gt;Please note that, as you have dimensioned the arrays, this will be very inefficient with cache line usage.&lt;/P&gt;
&lt;P&gt;Rework your code to use:&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;    REAL (KIND(0.0)), DIMENSION(2,jmax,lmax, Nbr_SSS) :: U2
    REAL (KIND(0.0)), DIMENSION(2,jmax,lmax, Nbr_SSS) :: Var1
&lt;/LI-CODE&gt;
&lt;P&gt;or possibly:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;    REAL (KIND(0.0)), DIMENSION(jmax,lmax, 2, Nbr_SSS) :: U2
    REAL (KIND(0.0)), DIMENSION(jmax,lmax, 2, Nbr_SSS) :: Var1
&lt;/LI-CODE&gt;
&lt;P&gt;Be aware the interations on jmax are on adjacent locations in memory.&lt;/P&gt;
&lt;P&gt;The Fortran dimension order for adjacent memory locations is inverse that of C/C++.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
    <pubDate>Wed, 10 May 2023 15:41:55 GMT</pubDate>
    <dc:creator>jimdempseyatthecove</dc:creator>
    <dc:date>2023-05-10T15:41:55Z</dc:date>
    <item>
      <title>Quenstion regarding weird bug with OpenMP parallelization</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Quenstion-regarding-weird-bug-with-OpenMP-parallelization/m-p/1484509#M166307</link>
      <description>&lt;P&gt;&lt;SPAN class="sub_section_element_selectors"&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="sub_section_element_selectors"&gt;so first I have to mention, that I am new to the Intel Fortran Compiler and there may be some obvious things that I am not doing/taking into account.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="sub_section_element_selectors"&gt;So I have recently switched to Intel fortran for the possibility of parallelisation. I am now using OpenMP to calculate many of the loops in my program that seemed to make sense in parallel and what I noticed is that the perfomance went faster and faster with more threads until around 15 threads and after that it started getting slower and slower (I have aaccess to a Server with 190 threads).&lt;BR /&gt;&lt;BR /&gt;I was looking for the issue and found this weird behaviour that I could replicate with a test program (copy below). When I have an empty parallel region inside of a loop with a larger array definition (below its U2 = U = 128x128x50x2), the program slows down if I use more and more loops.&lt;BR /&gt;Even in the case where the arrays U and U2 are empty and the parallel region is completely empty as well. &lt;BR /&gt;And if I deactivate the parallel region or delete the array definition it goes as fast as usual. If I calculate the array definition and the empty parallel region inside of two different loops it also goes fast.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="sub_section_element_selectors"&gt;So maybe there seems to be some sort of memory problem or false sharing or something? I could not find any answers what is happening here which is why I was hoping some of you could help me out, it would be much appreciated. Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="sub_section_element_selectors"&gt;---------------------&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV&gt;program Test_Parallel2&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;USE omp_lib&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; IMPLICIT NONE&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;INTEGER, parameter :: jmax=128, lmax=128, Nbr_S=1, Nbr_SSS=50&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; REAL (KIND(0.0)), DIMENSION(100) :: Simulation_Time&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; REAL (KIND(0.0)), DIMENSION(Nbr_SSS,2,jmax,lmax) :: U&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; INTEGER :: Time1, Time2, rate&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; INTEGER :: iMaxThreads, kmax, k&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; REAL (KIND(0.0)) :: total_time&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; REAL (KIND(0.0)), DIMENSION(Nbr_SSS,2,jmax,lmax) :: U2&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; REAL (KIND(0.0)), DIMENSION(Nbr_SSS,2,jmax,lmax) :: Var1&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; !Intital Definitions&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; kmax = 50&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Simulation_Time = 0.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; U = 0.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; U2=0.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; !$ iMaxThreads = OMP_GET_MAX_THREADS()&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; !$ iMaxThreads = 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; !I override the number of active threads here for test purposes&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; !$ call&amp;nbsp; &amp;nbsp; OMP_SET_NUM_THREADS(iMaxThreads-1)&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; !$ Print *, "OpenMP active", iMaxThreads&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;CALL system_clock(count_rate=rate)&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; CALL SYSTEM_CLOCK(Time1)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DO k=1, kmax, 1&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; U2(:,:,:,:) = U(:,:,:,:)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; !$OMP PARALLEL&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; !$OMP END PARALLEL&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;END DO&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; CALL SYSTEM_CLOCK(Time2)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; total_time = real(Time2-Time1)/real(rate)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; write(*,*) 'Time taken (s):', total_time&lt;/DIV&gt;
&lt;DIV&gt;PAUSE 10&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;end program Test_Parallel2&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN class="sub_section_element_selectors"&gt;---------------------&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="sub_section_element_selectors"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 14:14:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Quenstion-regarding-weird-bug-with-OpenMP-parallelization/m-p/1484509#M166307</guid>
      <dc:creator>Marius13</dc:creator>
      <dc:date>2023-05-09T14:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Quenstion regarding weird bug with OpenMP parallelization</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Quenstion-regarding-weird-bug-with-OpenMP-parallelization/m-p/1484511#M166308</link>
      <description>&lt;P&gt;Maybe some information on the compiler properties that I am using:&lt;BR /&gt;&lt;BR /&gt;/nologo /MP /O1 /assume:buffered_io /heap-arrays0 /Qopenmp /fp:strict /module:"x64\Release\\" /object:"x64\Release\\" /Fd"x64\Release\vc170.pdb" /libs:static /threads /Qmkl:sequential /c&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Also, in the Linker-&amp;gt;System configuration I set the Stack Reserve Size pretty high at around&amp;nbsp;500000000 - otherwise I get an overflow error.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 14:18:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Quenstion-regarding-weird-bug-with-OpenMP-parallelization/m-p/1484511#M166308</guid>
      <dc:creator>Marius13</dc:creator>
      <dc:date>2023-05-09T14:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Quenstion regarding weird bug with OpenMP parallelization</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Quenstion-regarding-weird-bug-with-OpenMP-parallelization/m-p/1484921#M166321</link>
      <description>&lt;P&gt;Running through an empty (or do nothing) parallel region (that is not removed/elided by compiler optimizations will incur the overhead of starting or resuming the thread team of that parallel region. More threads, more overhead. It is only when the parallel region has sufficient parallizable code to surpass the overhead that parallelization becomes effective.&lt;/P&gt;
&lt;P&gt;Note, your parallel region (of your actual project) may contain serialized (critical) sections, which will intercede with parallization for that section of code. Some system functions have critical sections. Examples: random number generators, memory allocation/deallocation. Also note that should "Reallocation of lefthand side" result in reallocation (memory deallocation and allocation) that those statements will serialize.&lt;/P&gt;
&lt;P&gt;Without seeing your real code, I will make an assumption:&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;    REAL (KIND(0.0)), DIMENSION(Nbr_SSS,2,jmax,lmax) :: U2
    REAL (KIND(0.0)), DIMENSION(Nbr_SSS,2,jmax,lmax) :: Var1
&lt;/LI-CODE&gt;
&lt;P&gt;that your intention is to have each thread work on an individual Nbr_SSS section of the arrays.&lt;/P&gt;
&lt;P&gt;Please note that, as you have dimensioned the arrays, this will be very inefficient with cache line usage.&lt;/P&gt;
&lt;P&gt;Rework your code to use:&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;    REAL (KIND(0.0)), DIMENSION(2,jmax,lmax, Nbr_SSS) :: U2
    REAL (KIND(0.0)), DIMENSION(2,jmax,lmax, Nbr_SSS) :: Var1
&lt;/LI-CODE&gt;
&lt;P&gt;or possibly:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;    REAL (KIND(0.0)), DIMENSION(jmax,lmax, 2, Nbr_SSS) :: U2
    REAL (KIND(0.0)), DIMENSION(jmax,lmax, 2, Nbr_SSS) :: Var1
&lt;/LI-CODE&gt;
&lt;P&gt;Be aware the interations on jmax are on adjacent locations in memory.&lt;/P&gt;
&lt;P&gt;The Fortran dimension order for adjacent memory locations is inverse that of C/C++.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 15:41:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Quenstion-regarding-weird-bug-with-OpenMP-parallelization/m-p/1484921#M166321</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2023-05-10T15:41:55Z</dc:date>
    </item>
  </channel>
</rss>

