title: No Speedup achieved using Parallel_Scan Component of Intel Thread Building Blocks (TBB)
body: <p>I am exploring Parallel_Scan component in Intel Thread Building Blocks which is used in case of an associative operation and i am finding that Parallel_Scan is taking 10 times more than it would have been done in serial. </p>
  
  <p>Code which i have written to check is:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include "tbb/task_scheduler_init.h"
  #include "tbb/blocked_range.h"
  #include "tbb/parallel_scan.h"
  #include "tbb/tick_count.h"
  
  using namespace std;
  using namespace tbb;
  
  template &lt;class T&gt;
  class Body 
  {
      T reduced_result;
      T* const y;
      const T* const x;
  
      public:
  
      Body( T y_[], const T x_[] ) : reduced_result(0), x(x_), y(y_) {}
  
      T get_reduced_result() const {return reduced_result;}
  
      template&lt;typename Tag&gt;
      void operator()( const blocked_range&lt;int&gt;&amp; r, Tag ) 
      {
          T temp = reduced_result;
  
          for( int i=r.begin(); i&lt;r.end(); ++i ) 
          {
              temp = temp+x[i];
              if( Tag::is_final_scan() )
              y[i] = temp;
          }
  
          reduced_result = temp;
      }
  
      Body( Body&amp; b, split ) : x(b.x), y(b.y), reduced_result(10) {}
  
      void reverse_join( Body&amp; a ) 
      {
          reduced_result = a.reduced_result + reduced_result;
      }
  
      void assign( Body&amp; b ) 
      {   
          reduced_result = b.reduced_result;
      }
  };
  
  
  template&lt;class T&gt;
  float DoParallelScan( T y[], const T x[], int n) 
  {
      Body&lt;int&gt; body(y,x);
      tick_count t1,t2,t3,t4;
      t1=tick_count::now();
      parallel_scan( blocked_range&lt;int&gt;(0,n), body , auto_partitioner() );
      t2=tick_count::now();
      cout&lt;&lt;"Time Taken for parallel scan is \t"&lt;&lt;(t2-t1).seconds()&lt;&lt;endl;
      return body.get_reduced_result();
  }
  
  
  template&lt;class T1&gt;
  float SerialScan(T1 y[], const T1 x[], int n)
  {
      tick_count t3,t4;
  
      t3=tick_count::now();
      T1 temp = 10;
  
      for( int i=1; i&lt;n; ++i ) 
      {
          temp = temp+x[i];
          y[i] = temp;
      }
      t4=tick_count::now();
      cout&lt;&lt;"Time Taken for serial  scan is \t"&lt;&lt;(t4-t3).seconds()&lt;&lt;endl;
      return temp;
  
  }
  
  
  int main()
  {
      task_scheduler_init init1;
  
      int y1[100000],x1[100000];
  
      for(int i=0;i&lt;100000;i++)
          x1[i]=i;
  
      cout&lt;&lt;fixed;
  
      cout&lt;&lt;"\n serial scan output is \t"&lt;&lt;SerialScan(y1,x1,100000)&lt;&lt;endl;
  
      cout&lt;&lt;"\n parallel scan output is \t"&lt;&lt;DoParallelScan(y1,x1,100000)&lt;&lt;endl;
  
      return 0;
  } 
  </code></pre>
  
  <p>Please help me in finding where i am going wrong.</p>