title: How to split up an all vs. all comparison into same sized chunks for parallelization?
body: <p>I know that this must be quite a basic use case, but I don't know what keywords to search for.</p>
  
  <p>Given a nested for loop like this:</p>
  
  <pre><code>for (i = 0; i &lt; size; i++) {
    for (j = i+1; j &lt; size; j++) {
      doComparision(i, j);
    }
  }
  </code></pre>
  
  <p>I know that I can calculate the total number of comparisons with n = size * (size-1) / 2.</p>
  
  <p>The problem is that I want to parallelize this loop. Each thread should do only a certain range of the outer for-loop:</p>
  
  <pre><code>for (i = beginOffset; i &lt;= endOffset; i++) {
    for (j = i+1; j &lt; size; j++) {
      doComparision(i, j);
    }
  }
  </code></pre>
  
  <p>How can I calculate the number of comparisons in such loops? </p>
  
  <p>In the end I want to make sure that each thread has roughly the same amount of work.</p>