title: Parallel Execution taking more time than Serial?
body: <p>i am studying task implementation in TBB and have run code for parallel and serial calculation of Fibonacci Series.</p>
  
  <p>The Code is :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;tbb/task.h&gt;
  #include &lt;tbb/task_group.h&gt;
  #include &lt;stdlib.h&gt;
  #include "tbb/compat/thread"
  #include "tbb/task_scheduler_init.h"
  using namespace std;
  using namespace tbb;
  
  #define CutOff 2
  
  long serialFib( long n ) {
  if( n&lt;2 )
  return n;
  else
  return serialFib(n-1) + serialFib(n-2);
  }
  
  
  class FibTask: public task 
  {
      public:
      const long n;
      long* const sum;
  
      FibTask( long n_, long* sum_ ) : n(n_), sum(sum_) {}
  
      task* execute() 
      {
          // cout&lt;&lt;"task id of thread is \t"&lt;&lt;this_thread::get_id()&lt;&lt;"FibTask(n)="&lt;&lt;n&lt;&lt;endl;  // Overrides virtual function task::execute    
                  // cout&lt;&lt;"Task Stolen is"&lt;&lt;is_stolen_task()&lt;&lt;endl;
          if( n&lt;CutOff ) 
          {
              *sum = serialFib(n);
          }
           else
           {
              long x, y;
              FibTask&amp; a = *new( allocate_child() ) FibTask(n-1,&amp;x);
              FibTask&amp; b = *new( allocate_child() ) FibTask(n-2,&amp;y);
              set_ref_count(3); // 3 = 2 children + 1 for wait // ref_countis used to keep track of the number of tasks spawned at                            the current level of the task graph
              spawn( b );
                        // cout&lt;&lt;"child id of thread is \t"&lt;&lt;this_thread::get_id()&lt;&lt;"calculating n ="&lt;&lt;n&lt;&lt;endl;
              spawn_and_wait_for_all( a ); //set tasks for execution and wait for them
              *sum = x+y;
          }
          return NULL;
      }
  };
  
  
  long parallelFib( long n ) 
  {
      long sum;
      FibTask&amp; a = *new(task::allocate_root()) FibTask(n,&amp;sum);
      task::spawn_root_and_wait(a);
      return sum;
  }
  
  
  int main()
  {     
       long i,j;
       cout&lt;&lt;fixed;
  
       cout&lt;&lt;"Fibonacci Series parallelly formed is "&lt;&lt;endl;
        tick_count t0=tick_count::now();
       for(i=0;i&lt;50;i++)
       cout&lt;&lt;parallelFib(i)&lt;&lt;"\t";
      // cout&lt;&lt;"parallel execution of Fibonacci series for n=10 \t"&lt;&lt;parallelFib(i)&lt;&lt;endl;
  
       tick_count t1=tick_count::now();
       double t=(t1-t0).seconds();
       cout&lt;&lt;"Time Elapsed in Parallel Execution is  \t"&lt;&lt;t&lt;&lt;endl;
       cout&lt;&lt;"\n Fibonacci Series Serially formed is "&lt;&lt;endl;
       tick_count t3=tick_count::now();
  
       for(j=0;j&lt;50;j++)
       cout&lt;&lt;serialFib(j)&lt;&lt;"\t";
       tick_count t4=tick_count::now();
       double t5=(t4-t3).seconds();
       cout&lt;&lt;"Time Elapsed in Serial  Execution is  \t"&lt;&lt;t5&lt;&lt;endl;
       return(0);
  }
  </code></pre>
  
  <p>Parallel Execution is taking more time as compared to serial execution.In this Parallel Execution took 2500 sec whereas serial took around 167 secs.
  Can anybody pls explain reason for this?</p>