<?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 evaluate the code here please in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/evaluate-the-code-here-please/m-p/1045480#M47808</link>
    <description>&lt;P&gt;hi all&lt;/P&gt;

&lt;P&gt;I have a question to ask here&lt;/P&gt;

&lt;P&gt;which of the below two codes do better on vectorization.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;do i=1,n
    if(LMASK(i))
    
    a(i)=b(i)*c(i)

    endif       
enddo&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;integer LMASKtemp = abs(LMASK)

do i=1,n
    
    a(i) = a(i)*(1-LMASKtemp) + LMASKtemp * b(i)*c(i) 
       
enddo&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jun 2015 15:00:01 GMT</pubDate>
    <dc:creator>aketh_t_</dc:creator>
    <dc:date>2015-06-19T15:00:01Z</dc:date>
    <item>
      <title>evaluate the code here please</title>
      <link>https://community.intel.com/t5/Software-Archive/evaluate-the-code-here-please/m-p/1045480#M47808</link>
      <description>&lt;P&gt;hi all&lt;/P&gt;

&lt;P&gt;I have a question to ask here&lt;/P&gt;

&lt;P&gt;which of the below two codes do better on vectorization.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;do i=1,n
    if(LMASK(i))
    
    a(i)=b(i)*c(i)

    endif       
enddo&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;integer LMASKtemp = abs(LMASK)

do i=1,n
    
    a(i) = a(i)*(1-LMASKtemp) + LMASKtemp * b(i)*c(i) 
       
enddo&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 15:00:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/evaluate-the-code-here-please/m-p/1045480#M47808</guid>
      <dc:creator>aketh_t_</dc:creator>
      <dc:date>2015-06-19T15:00:01Z</dc:date>
    </item>
    <item>
      <title>Try:   WHERE(LMASK) A=B*C</title>
      <link>https://community.intel.com/t5/Software-Archive/evaluate-the-code-here-please/m-p/1045481#M47809</link>
      <description>&lt;P&gt;Try:&amp;nbsp;&amp;nbsp; WHERE(LMASK) A=B*C&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 19:27:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/evaluate-the-code-here-please/m-p/1045481#M47809</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2015-06-19T19:27:41Z</dc:date>
    </item>
    <item>
      <title>First, the 2 cases aren't</title>
      <link>https://community.intel.com/t5/Software-Archive/evaluate-the-code-here-please/m-p/1045482#M47810</link>
      <description>&lt;P&gt;First, the 2 cases aren't nearly equivalent.&amp;nbsp; A loop invariant conditional like your second version doesn't need any major effort, let alone non-portable stuff, to optimize. So I'll talk the case where the condition is not loop invariant.&lt;/P&gt;

&lt;P&gt;As you wrote it, the first case would need a simd or vector always directive to vectorize, to give the compiler permission to dispense with ability to capture floating point exceptions.&amp;nbsp; Without the directive, the vectorizer would decline on the grounds of "protects exception."&lt;/P&gt;

&lt;P&gt;Your second case is reminiscent of Fortran 77, where one might write an expression using the SIGN intrinsic to calculate your LMASKtemp, if it were not loop invariant.&amp;nbsp; It should not require directives for vectorization even in the non-invariant case.&lt;/P&gt;

&lt;P&gt;a = merge(0., &amp;nbsp;a, LMASK) + merge( b, 0., LMASK) * c&amp;nbsp;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;might be preferable in my opinion, as it should vectorize with various known compilers, without a directive, and takes full advantage of AVX2 instructions.&amp;nbsp; Of course, there are cases involving non-finite operands where it's not equivalent to your version.&amp;nbsp; For example, if c had an infinity corresponding with a .false. mask, the result would be NaN.&amp;nbsp; That's the price paid for writing an almost similar version which avoids "protects exception."&lt;/P&gt;

&lt;P&gt;The methods involving lots of arithmetic may be as efficient as the others on Intel instruction sets prior to the introduction of blend.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 19:55:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/evaluate-the-code-here-please/m-p/1045482#M47810</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2015-06-19T19:55:00Z</dc:date>
    </item>
  </channel>
</rss>

