message: Factor out element counting code in Mesh::GeneratePartitioning
diff: @@ -6541,6 +6541,12 @@ int *Mesh::GeneratePartitioning(int nparts, int part_method)
  {
  Array< Pair<int,int> > psize(nparts);
  int empty_parts;
  +
  + // Count how many elements are in each partition, and store the result in
  + // psize, where psize[i].one is the number of elements, and psize[i].two
  + // is partition index. Keep track of the number of empty parts.
  + auto count_partition_elements = [&]()
  + {
  for (i = 0; i < nparts; i++)
  {
  psize[i].one = 0;
  @@ -6557,6 +6563,9 @@ int *Mesh::GeneratePartitioning(int nparts, int part_method)
  {
  if (psize[i].one == 0) { empty_parts++; }
  }
  + };
  +
  + count_partition_elements();
  // This code just split the largest partitionings in two.
  // Do we need to replace it with something better?
  @@ -6593,23 +6602,7 @@ int *Mesh::GeneratePartitioning(int nparts, int part_method)
  }
  // Check for empty partitionings again
  - for (i = 0; i < nparts; i++)
  - {
  - psize[i].one = 0;
  - psize[i].two = i;
  - }
  -
  - for (i = 0; i < NumOfElements; i++)
  - {
  - psize[partitioning[i]].one++;
  - }
  -
  - empty_parts = 0;
  - for (i = 0; i < nparts; i++)
  - {
  - if (psize[i].one == 0) { empty_parts++; }
  - }
  -
  + count_partition_elements();
  }
  }
  