title: tasks run in thread takes longer than in serial?
body: <p>So im doing some computation on 4 million nodes.</p>
  
  <p>the very bask serial version just have a for loop which loops 4 million times and do 4 million times of computation. this takes roughly 1.2 sec.</p>
  
  <p>when I split the for loop to, say, 4 for loops and each does 1/4 of the computation, the total time became 1.9 sec. </p>
  
  <p>I guess there are some overhead in creating for loops and maybe has to do with cpu likes to compute data in chunk.</p>
  
  <p>The real thing bothers me is when I try to put 4 loops to 4 thread on a 8 core machine, each thread would take 0.9 seconds to finish. 
  I am expecting each of them to only take 1.9/4 second instead.</p>
  
  <p>I dont think there are any race condition or synchronize issue since all I do was having a for loop to create 4 threads, which took 200 microseconds. And then a for loop to joins them.</p>
  
  <p>The computation read from a shared array and write to a different shared array.
  I am sure they are not writing to the same byte.</p>
  
  <p>Where could the overhead came from?</p>
  
  <p>main: ncores: number of cores.  node_size: size of graph (4 million node)</p>
  
  <pre><code>        for(i = 0 ; i &lt; ncores ; i++){
              int *t = (int*)malloc(sizeof(int));
              *t = i;
              int iret = pthread_create( &amp;thread[i], NULL, calculate_rank_p, (void*)(t));
  
          }
          for (i = 0; i &lt; ncores; i++)
          {
              pthread_join(thread[i], NULL);
          }
  </code></pre>
  
  <p>calculate_rank_p: vector is the rank vector for page rank calculation</p>
  
  <pre><code>Void *calculate_rank_pthread(void *argument) {
      int index = *(int*)argument;
      for(i = index; i &lt; node_size ; i+=ncores)     
         current_vector[i] = calc_r(i, vector);
      return NULL;     
  }
  </code></pre>
  
  <p>calc_r: this is just a page rank calculation using compressed row format.</p>
  
  <pre><code>double calc_r(int i, double *vector){
      double prank = 0;
      int j;
      for(j = row_ptr[i]; j &lt; row_ptr[i+1]; j++){
          prank += vector[col_ind[j]] * val[j];
      }
      return prank;
  }
  </code></pre>
  
  <p>everything that is not declared are global variable</p>