<?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 slowdown when traversing a stl container in parallel (openmp) in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/slowdown-when-traversing-a-stl-container-in-parallel-openmp/m-p/900163#M4195</link>
    <description>&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am
trying to parallelize an existing seriell programm with openMP. Thereby
I encountered a severe problem while traversing stl-containers. It
seems like traversing a stl container with an (bi-directional) iterator does hurt
parallel performance strongly! Using random access iterators [..], the slow down does not occur. But I cannot see the reason for this behaviour...?&lt;BR /&gt;&lt;BR /&gt;I
tested following two loops on a quadro core intel machine with different compilers (also an intel compiler). The first
loop has a speedup of nearly 4, as expected, whereas the second loop
executes more than 10 times slower(!) than the serial code.&lt;BR /&gt;&lt;BR /&gt;1.) this works fine, nice speedup!&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;&lt;FONT face="Arial" size="3"&gt;&lt;I&gt;&lt;FONT color="#008000"&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;vector&amp;lt; double &amp;gt; vec;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int k=0;k&amp;lt;100000;k++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;vec.push_back(0.0);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#pragma omp parallel for&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int i=0; i&amp;lt;4; i++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;for (int index=0;index&lt;VEC.SIZE&gt;{&lt;BR /&gt;&lt;DIV&gt;//do ntothing&lt;BR /&gt;&lt;/DIV&gt;}&lt;BR /&gt;&lt;/VEC.SIZE&gt;&lt;/DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;2.) this is very slow, lags even behind the serial code!&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;&lt;FONT face="Arial"&gt;&lt;I&gt;&lt;FONT color="#008000"&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;vector&amp;lt; double &amp;gt; vec;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int k=0;k&amp;lt;100000;k++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;vec.push_back(0.0);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#pragma omp parallel for&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int i=0; i&amp;lt;4; i++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;vector&amp;lt; double &amp;gt;::const_iterator iter;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (iter=vec.begin();iter!=vec.end();iter++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;//do nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;BR /&gt;(So, the vector is shared, while the index-variable or the iterator are private to each thread. )&lt;BR /&gt;&lt;BR /&gt;I
cannot understand why traversing a stl container may hurt the
performance in such a way. Are there some hidden conflicts in the implementations of the stl::vector class? Does somebody know what may cause this problem? &lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;Christian&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;</description>
    <pubDate>Wed, 23 Apr 2008 07:31:06 GMT</pubDate>
    <dc:creator>holomorph</dc:creator>
    <dc:date>2008-04-23T07:31:06Z</dc:date>
    <item>
      <title>slowdown when traversing a stl container in parallel (openmp)</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/slowdown-when-traversing-a-stl-container-in-parallel-openmp/m-p/900163#M4195</link>
      <description>&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am
trying to parallelize an existing seriell programm with openMP. Thereby
I encountered a severe problem while traversing stl-containers. It
seems like traversing a stl container with an (bi-directional) iterator does hurt
parallel performance strongly! Using random access iterators [..], the slow down does not occur. But I cannot see the reason for this behaviour...?&lt;BR /&gt;&lt;BR /&gt;I
tested following two loops on a quadro core intel machine with different compilers (also an intel compiler). The first
loop has a speedup of nearly 4, as expected, whereas the second loop
executes more than 10 times slower(!) than the serial code.&lt;BR /&gt;&lt;BR /&gt;1.) this works fine, nice speedup!&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;&lt;FONT face="Arial" size="3"&gt;&lt;I&gt;&lt;FONT color="#008000"&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;vector&amp;lt; double &amp;gt; vec;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int k=0;k&amp;lt;100000;k++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;vec.push_back(0.0);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#pragma omp parallel for&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int i=0; i&amp;lt;4; i++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;for (int index=0;index&lt;VEC.SIZE&gt;{&lt;BR /&gt;&lt;DIV&gt;//do ntothing&lt;BR /&gt;&lt;/DIV&gt;}&lt;BR /&gt;&lt;/VEC.SIZE&gt;&lt;/DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;2.) this is very slow, lags even behind the serial code!&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;&lt;FONT face="Arial"&gt;&lt;I&gt;&lt;FONT color="#008000"&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;SPAN&gt;vector&amp;lt; double &amp;gt; vec;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int k=0;k&amp;lt;100000;k++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;vec.push_back(0.0);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#pragma omp parallel for&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int i=0; i&amp;lt;4; i++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;vector&amp;lt; double &amp;gt;::const_iterator iter;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (iter=vec.begin();iter!=vec.end();iter++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;//do nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;SPAN id="_ctl0_MainContent_PostFlatView"&gt;&lt;SPAN&gt;&lt;BR /&gt;(So, the vector is shared, while the index-variable or the iterator are private to each thread. )&lt;BR /&gt;&lt;BR /&gt;I
cannot understand why traversing a stl container may hurt the
performance in such a way. Are there some hidden conflicts in the implementations of the stl::vector class? Does somebody know what may cause this problem? &lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;Christian&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;</description>
      <pubDate>Wed, 23 Apr 2008 07:31:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/slowdown-when-traversing-a-stl-container-in-parallel-openmp/m-p/900163#M4195</guid>
      <dc:creator>holomorph</dc:creator>
      <dc:date>2008-04-23T07:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: slowdown when traversing a stl container in parallel (openm</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/slowdown-when-traversing-a-stl-container-in-parallel-openmp/m-p/900164#M4196</link>
      <description>Hi together,&lt;BR /&gt;&lt;BR /&gt;...actually this problem was due to my wrong compiler settings. I tested the speedups during "DEBUG" mode which seems to have caused these weird slowdowns. I am not sure what is the reason for these slowdowns during debugging, but with settings in the "RELEASE" mode the speedup is as expected.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Apr 2008 06:38:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/slowdown-when-traversing-a-stl-container-in-parallel-openmp/m-p/900164#M4196</guid>
      <dc:creator>holomorph</dc:creator>
      <dc:date>2008-04-24T06:38:40Z</dc:date>
    </item>
  </channel>
</rss>

