@Test public void testGetUniformCounts() { for (int taskCount = 1; taskCount < 100; taskCount++) { final int elementCount = 10000; final List<Integer> retVals = ScatterHelper.getUniformCounts(elementCount, taskCount); int sum = 0; int maxVal = Integer.MIN_VALUE; int minVal = Integer.MAX_VALUE; int prevVal = Integer.MAX_VALUE; for (final int retVal : retVals) { sum += retVal; maxVal = retVal > maxVal ? retVal : maxVal; minVal = retVal < minVal ? retVal : minVal; assertTrue(prevVal >= retVal); prevVal = retVal; } assertEquals(elementCount, sum); assertEquals(maxVal - minVal, elementCount % taskCount == 0 ? 0 : 1); } }
public static List<Integer> getUniformCounts(final int elementCount, final int taskCount) { final int quotient = elementCount / taskCount; final int remainder = elementCount % taskCount; final List<Integer> retList = new ArrayList<>(); for (int taskIndex = 0; taskIndex < taskCount; taskIndex++) { if (taskIndex < remainder) { retList.add(quotient + 1); } else { retList.add(quotient); } } return retList; }
ScatterHelper { public static List<Integer> getUniformCounts(final int elementCount, final int taskCount) { final int quotient = elementCount / taskCount; final int remainder = elementCount % taskCount; final List<Integer> retList = new ArrayList<>(); for (int taskIndex = 0; taskIndex < taskCount; taskIndex++) { if (taskIndex < remainder) { retList.add(quotient + 1); } else { retList.add(quotient); } } return retList; } }
ScatterHelper { public static List<Integer> getUniformCounts(final int elementCount, final int taskCount) { final int quotient = elementCount / taskCount; final int remainder = elementCount % taskCount; final List<Integer> retList = new ArrayList<>(); for (int taskIndex = 0; taskIndex < taskCount; taskIndex++) { if (taskIndex < remainder) { retList.add(quotient + 1); } else { retList.add(quotient); } } return retList; } private  ScatterHelper(); }
ScatterHelper { public static List<Integer> getUniformCounts(final int elementCount, final int taskCount) { final int quotient = elementCount / taskCount; final int remainder = elementCount % taskCount; final List<Integer> retList = new ArrayList<>(); for (int taskIndex = 0; taskIndex < taskCount; taskIndex++) { if (taskIndex < remainder) { retList.add(quotient + 1); } else { retList.add(quotient); } } return retList; } private  ScatterHelper(); static List<Integer> getUniformCounts(final int elementCount, final int taskCount); }
ScatterHelper { public static List<Integer> getUniformCounts(final int elementCount, final int taskCount) { final int quotient = elementCount / taskCount; final int remainder = elementCount % taskCount; final List<Integer> retList = new ArrayList<>(); for (int taskIndex = 0; taskIndex < taskCount; taskIndex++) { if (taskIndex < remainder) { retList.add(quotient + 1); } else { retList.add(quotient); } } return retList; } private  ScatterHelper(); static List<Integer> getUniformCounts(final int elementCount, final int taskCount);  }