title: Parallel sum of elements in a large Array
body: <p>I have program that sums the elements in a very large array. I want to parallelize this sum.</p>
  
  <pre><code>#define N = some_very_large_no; // say 1e12
  float x[N]; // read from a file
  float sum=0.0;
  main()
  {
  
  for (i=0, i&lt;N, i++)
  
  sum=sum+x[i];
  
  }
  </code></pre>
  
  <p>How can I parallelize this sum using threads (c/c++/Java any code example is fine)? How many threads should I use if there is 8 cores in the machine for optimal performance?</p>
  
  <p>EDIT: N may be really large ( larger than 1e6 actually) and varies based on the file size I read the data from. The file is in the order of GBs. </p>
  
  <p>Edit: N is changed to a large value (1e12 to 1e16)</p>