title: How much can this c/c++ loop be optimized?
body: <p>I am a newbie on optimization. I have been reading some reference on how to optimize c++ code but I have a hard time applying it to real code. Therefore I just want to gather some real world optimization technique on how to squeeze as much juice from the CPU/Memory as possible from the loop below</p>
  
  <pre><code>double sum = 0, *array;
  array = (double*) malloc(T * sizeof(double));
  for(int t = 0; t &lt; T; ++t){
  sum += fun(a,b,c,d,e,f,sum);
  *(array+t) = sum;
  }
  </code></pre>
  
  <p>where <code>a,b,c,d,e,f</code> are <code>double</code> and <code>T</code> is <code>int</code>. Anything including but not limited to memory alignment, parallelism, openmp/MPI, and SSE instructions are welcome. Compiler is standard gcc, microsoft, or commonly available compiler. If the solution is compiler specific, please specific compiler and any option flag associate with your solution. </p>
  
  <p>Thanks!</p>
  
  <p>PS: Forgot to mention properties <code>fun</code>. Please assume that it is a simple function with no loop inside, and compose of only basic arithmetic operation. Simply think of it as an inline function. </p>
  
  <p>EDIT2: since the details of <code>fun</code> is important, please forget the parameter c, d, e, f and assume <code>fun</code> is defined as</p>
  
  <pre><code>inline double fun(a,b, sum){
  return sum + a* ( b - sum);
  }
  </code></pre>